Rename option to shell-command-dont-erase-buffer
[emacs.git] / src / frame.c
blob6de55e46c093fde396c934f171fda16c5a3433c7
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2016 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <errno.h>
24 #include <limits.h>
26 #include <c-ctype.h>
28 #include "lisp.h"
30 #ifdef HAVE_WINDOW_SYSTEM
31 #include TERM_HEADER
32 #endif /* HAVE_WINDOW_SYSTEM */
34 #include "buffer.h"
35 /* These help us bind and responding to switch-frame events. */
36 #include "keyboard.h"
37 #include "frame.h"
38 #include "blockinput.h"
39 #include "termchar.h"
40 #include "termhooks.h"
41 #include "dispextern.h"
42 #include "window.h"
43 #ifdef HAVE_WINDOW_SYSTEM
44 #include "fontset.h"
45 #endif
46 #include "cm.h"
47 #ifdef MSDOS
48 #include "msdos.h"
49 #include "dosfns.h"
50 #endif
51 #ifdef USE_X_TOOLKIT
52 #include "widget.h"
53 #endif
55 /* The currently selected frame. */
57 Lisp_Object selected_frame;
59 /* A frame which is not just a mini-buffer, or NULL if there are no such
60 frames. This is usually the most recent such frame that was selected. */
62 static struct frame *last_nonminibuf_frame;
64 /* False means there are no visible garbaged frames. */
65 bool frame_garbaged;
67 /* The default tool bar height for future frames. */
68 #if defined USE_GTK || defined HAVE_NS
69 enum { frame_default_tool_bar_height = 0 };
70 #else
71 int frame_default_tool_bar_height;
72 #endif
74 #ifdef HAVE_WINDOW_SYSTEM
75 static void x_report_frame_params (struct frame *, Lisp_Object *);
76 #endif
78 /* These setters are used only in this file, so they can be private. */
79 static void
80 fset_buffer_predicate (struct frame *f, Lisp_Object val)
82 f->buffer_predicate = val;
84 static void
85 fset_minibuffer_window (struct frame *f, Lisp_Object val)
87 f->minibuffer_window = val;
90 struct frame *
91 decode_live_frame (register Lisp_Object frame)
93 if (NILP (frame))
94 frame = selected_frame;
95 CHECK_LIVE_FRAME (frame);
96 return XFRAME (frame);
99 struct frame *
100 decode_any_frame (register Lisp_Object frame)
102 if (NILP (frame))
103 frame = selected_frame;
104 CHECK_FRAME (frame);
105 return XFRAME (frame);
108 #ifdef HAVE_WINDOW_SYSTEM
109 bool
110 display_available (void)
112 return x_display_list != NULL;
114 #endif
116 struct frame *
117 decode_window_system_frame (Lisp_Object frame)
119 struct frame *f = decode_live_frame (frame);
120 check_window_system (f);
121 #ifdef HAVE_WINDOW_SYSTEM
122 return f;
123 #endif
126 void
127 check_window_system (struct frame *f)
129 #ifdef HAVE_WINDOW_SYSTEM
130 if (window_system_available (f))
131 return;
132 #endif
133 error (f ? "Window system frame should be used"
134 : "Window system is not in use or not initialized");
137 /* Return the value of frame parameter PROP in frame FRAME. */
139 Lisp_Object
140 get_frame_param (register struct frame *frame, Lisp_Object prop)
142 register Lisp_Object tem;
144 tem = Fassq (prop, frame->param_alist);
145 if (EQ (tem, Qnil))
146 return tem;
147 return Fcdr (tem);
151 void
152 frame_size_history_add (struct frame *f, Lisp_Object fun_symbol,
153 int width, int height, Lisp_Object rest)
155 Lisp_Object frame;
157 XSETFRAME (frame, f);
158 if (CONSP (frame_size_history)
159 && INTEGERP (XCAR (frame_size_history))
160 && 0 < XINT (XCAR (frame_size_history)))
161 frame_size_history =
162 Fcons (make_number (XINT (XCAR (frame_size_history)) - 1),
163 Fcons (list4
164 (frame, fun_symbol,
165 ((width > 0)
166 ? list4 (make_number (FRAME_TEXT_WIDTH (f)),
167 make_number (FRAME_TEXT_HEIGHT (f)),
168 make_number (width),
169 make_number (height))
170 : Qnil),
171 rest),
172 XCDR (frame_size_history)));
176 /* Return 1 if `frame-inhibit-implied-resize' is non-nil or fullscreen
177 state of frame F would be affected by a vertical (horizontal if
178 HORIZONTAL is true) resize. PARAMETER is the symbol of the frame
179 parameter that is changed. */
180 bool
181 frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter)
183 Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
184 bool inhibit
185 = (f->after_make_frame
186 ? (EQ (frame_inhibit_implied_resize, Qt)
187 || (CONSP (frame_inhibit_implied_resize)
188 && !NILP (Fmemq (parameter, frame_inhibit_implied_resize)))
189 || (horizontal
190 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullheight))
191 || (!horizontal
192 && !EQ (fullscreen, Qnil) && !EQ (fullscreen, Qfullwidth))
193 || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f))
194 : ((horizontal && f->inhibit_horizontal_resize)
195 || (!horizontal && f->inhibit_vertical_resize)));
196 if (inhibit && !FRAME_TERMCAP_P (f) && !FRAME_MSDOS_P (f))
197 frame_size_history_add
198 (f, Qframe_inhibit_resize, 0, 0,
199 list5 (horizontal ? Qt : Qnil, parameter,
200 f->after_make_frame ? Qt : Qnil,
201 frame_inhibit_implied_resize,
202 fullscreen));
204 return inhibit;
207 static void
208 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
210 int nlines;
211 int olines = FRAME_MENU_BAR_LINES (f);
213 /* Right now, menu bars don't work properly in minibuf-only frames;
214 most of the commands try to apply themselves to the minibuffer
215 frame itself, and get an error because you can't switch buffers
216 in or split the minibuffer window. */
217 if (FRAME_MINIBUF_ONLY_P (f))
218 return;
220 if (TYPE_RANGED_INTEGERP (int, value))
221 nlines = XINT (value);
222 else
223 nlines = 0;
225 if (nlines != olines)
227 windows_or_buffers_changed = 14;
228 FRAME_MENU_BAR_LINES (f) = nlines;
229 FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
230 change_frame_size (f, FRAME_COLS (f),
231 FRAME_LINES (f) + olines - nlines,
232 0, 1, 0, 0);
236 Lisp_Object Vframe_list;
239 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
240 doc: /* Return non-nil if OBJECT is a frame.
241 Value is:
242 t for a termcap frame (a character-only terminal),
243 `x' for an Emacs frame that is really an X window,
244 `w32' for an Emacs frame that is a window on MS-Windows display,
245 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
246 `pc' for a direct-write MS-DOS frame.
247 See also `frame-live-p'. */)
248 (Lisp_Object object)
250 if (!FRAMEP (object))
251 return Qnil;
252 switch (XFRAME (object)->output_method)
254 case output_initial: /* The initial frame is like a termcap frame. */
255 case output_termcap:
256 return Qt;
257 case output_x_window:
258 return Qx;
259 case output_w32:
260 return Qw32;
261 case output_msdos_raw:
262 return Qpc;
263 case output_ns:
264 return Qns;
265 default:
266 emacs_abort ();
270 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
271 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
272 Value is nil if OBJECT is not a live frame. If object is a live
273 frame, the return value indicates what sort of terminal device it is
274 displayed on. See the documentation of `framep' for possible
275 return values. */)
276 (Lisp_Object object)
278 return ((FRAMEP (object)
279 && FRAME_LIVE_P (XFRAME (object)))
280 ? Fframep (object)
281 : Qnil);
284 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
285 doc: /* The name of the window system that FRAME is displaying through.
286 The value is a symbol:
287 nil for a termcap frame (a character-only terminal),
288 `x' for an Emacs frame that is really an X window,
289 `w32' for an Emacs frame that is a window on MS-Windows display,
290 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
291 `pc' for a direct-write MS-DOS frame.
293 FRAME defaults to the currently selected frame.
295 Use of this function as a predicate is deprecated. Instead,
296 use `display-graphic-p' or any of the other `display-*-p'
297 predicates which report frame's specific UI-related capabilities. */)
298 (Lisp_Object frame)
300 Lisp_Object type;
301 if (NILP (frame))
302 frame = selected_frame;
304 type = Fframep (frame);
306 if (NILP (type))
307 wrong_type_argument (Qframep, frame);
309 if (EQ (type, Qt))
310 return Qnil;
311 else
312 return type;
315 /* Placeholder used by temacs -nw before window.el is loaded. */
316 DEFUN ("frame-windows-min-size", Fframe_windows_min_size,
317 Sframe_windows_min_size, 4, 4, 0,
318 doc: /* */
319 attributes: const)
320 (Lisp_Object frame, Lisp_Object horizontal,
321 Lisp_Object ignore, Lisp_Object pixelwise)
323 return make_number (0);
326 static int
327 frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal,
328 Lisp_Object ignore, Lisp_Object pixelwise)
330 return XINT (call4 (Qframe_windows_min_size, frame, horizontal,
331 ignore, pixelwise));
335 /* Make sure windows sizes of frame F are OK. new_width and new_height
336 are in pixels. A value of -1 means no change is requested for that
337 size (but the frame may still have to be resized to accommodate
338 windows with their minimum sizes). This can either issue a request
339 to resize the frame externally (via x_set_window_size), to resize the
340 frame internally (via resize_frame_windows) or do nothing at all.
342 The argument INHIBIT can assume the following values:
344 0 means to unconditionally call x_set_window_size even if sizes
345 apparently do not change. Fx_create_frame uses this to pass the
346 initial size to the window manager.
348 1 means to call x_set_window_size if the outer frame size really
349 changes. Fset_frame_size, Fset_frame_height, ... use this.
351 2 means to call x_set_window_size provided frame_inhibit_resize
352 allows it. The menu and tool bar code use this ("3" won't work
353 here in general because menu and tool bar are often not counted in
354 the frame's text height).
356 3 means call x_set_window_size if window minimum sizes must be
357 preserved or frame_inhibit_resize allows it. x_set_left_fringe,
358 x_set_scroll_bar_width, x_new_font ... use (or should use) this.
360 4 means call x_set_window_size only if window minimum sizes must be
361 preserved. x_set_right_divider_width, x_set_border_width and the
362 code responsible for wrapping the tool bar use this.
364 5 means to never call x_set_window_size. change_frame_size uses
365 this.
367 Note that even when x_set_window_size is not called, individual
368 windows may have to be resized (via `window--sanitize-window-sizes')
369 in order to support minimum size constraints.
371 PRETEND is as for change_frame_size. PARAMETER, if non-nil, is the
372 symbol of the parameter changed (like `menu-bar-lines', `font', ...).
373 This is passed on to frame_inhibit_resize to let the latter decide on
374 a case-by-case basis whether the frame may be resized externally. */
375 void
376 adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
377 bool pretend, Lisp_Object parameter)
379 int unit_width = FRAME_COLUMN_WIDTH (f);
380 int unit_height = FRAME_LINE_HEIGHT (f);
381 int old_pixel_width = FRAME_PIXEL_WIDTH (f);
382 int old_pixel_height = FRAME_PIXEL_HEIGHT (f);
383 int old_cols = FRAME_COLS (f);
384 int old_lines = FRAME_LINES (f);
385 int new_pixel_width, new_pixel_height;
386 /* The following two values are calculated from the old frame pixel
387 sizes and any "new" settings for tool bar, menu bar and internal
388 borders. We do it this way to detect whether we have to call
389 x_set_window_size as consequence of the new settings. */
390 int windows_width = FRAME_WINDOWS_WIDTH (f);
391 int windows_height = FRAME_WINDOWS_HEIGHT (f);
392 int min_windows_width, min_windows_height;
393 /* These are a bit tedious, maybe we should use a macro. */
394 struct window *r = XWINDOW (FRAME_ROOT_WINDOW (f));
395 int old_windows_width = WINDOW_PIXEL_WIDTH (r);
396 int old_windows_height
397 = (WINDOW_PIXEL_HEIGHT (r)
398 + ((FRAME_HAS_MINIBUF_P (f) && !FRAME_MINIBUF_ONLY_P (f))
399 ? WINDOW_PIXEL_HEIGHT (XWINDOW (FRAME_MINIBUF_WINDOW (f)))
400 : 0));
401 int new_windows_width, new_windows_height;
402 int old_text_width = FRAME_TEXT_WIDTH (f);
403 int old_text_height = FRAME_TEXT_HEIGHT (f);
404 /* If a size is < 0 use the old value. */
405 int new_text_width = (new_width >= 0) ? new_width : old_text_width;
406 int new_text_height = (new_height >= 0) ? new_height : old_text_height;
407 int new_cols, new_lines;
408 bool inhibit_horizontal, inhibit_vertical;
409 Lisp_Object frame;
411 XSETFRAME (frame, f);
413 frame_size_history_add
414 (f, Qadjust_frame_size_1, new_text_width, new_text_height,
415 list2 (parameter, make_number (inhibit)));
417 /* The following two values are calculated from the old window body
418 sizes and any "new" settings for scroll bars, dividers, fringes and
419 margins (though the latter should have been processed already). */
420 min_windows_width
421 = frame_windows_min_size (frame, Qt, (inhibit == 5) ? Qt : Qnil, Qt);
422 min_windows_height
423 = frame_windows_min_size (frame, Qnil, (inhibit == 5) ? Qt : Qnil, Qt);
425 if (inhibit >= 2 && inhibit <= 4)
426 /* When INHIBIT is in [2..4] inhibit if the "old" window sizes stay
427 within the limits and either resizing is inhibited or INHIBIT
428 equals 4. */
430 inhibit_horizontal = (windows_width >= min_windows_width
431 && (inhibit == 4
432 || frame_inhibit_resize (f, true, parameter)));
433 inhibit_vertical = (windows_height >= min_windows_height
434 && (inhibit == 4
435 || frame_inhibit_resize (f, false, parameter)));
437 else
438 /* Otherwise inhibit if INHIBIT equals 5. */
439 inhibit_horizontal = inhibit_vertical = inhibit == 5;
441 new_pixel_width = ((inhibit_horizontal && (inhibit < 5))
442 ? old_pixel_width
443 : max (FRAME_TEXT_TO_PIXEL_WIDTH (f, new_text_width),
444 min_windows_width
445 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
446 new_windows_width = new_pixel_width - 2 * FRAME_INTERNAL_BORDER_WIDTH (f);
447 new_text_width = FRAME_PIXEL_TO_TEXT_WIDTH (f, new_pixel_width);
448 new_cols = new_text_width / unit_width;
450 new_pixel_height = ((inhibit_vertical && (inhibit < 5))
451 ? old_pixel_height
452 : max (FRAME_TEXT_TO_PIXEL_HEIGHT (f, new_text_height),
453 min_windows_height
454 + FRAME_TOP_MARGIN_HEIGHT (f)
455 + 2 * FRAME_INTERNAL_BORDER_WIDTH (f)));
456 new_windows_height = (new_pixel_height
457 - FRAME_TOP_MARGIN_HEIGHT (f)
458 - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
459 new_text_height = FRAME_PIXEL_TO_TEXT_HEIGHT (f, new_pixel_height);
460 new_lines = new_text_height / unit_height;
462 #ifdef HAVE_WINDOW_SYSTEM
463 if (FRAME_WINDOW_P (f)
464 && f->can_x_set_window_size
465 && ((!inhibit_horizontal
466 && (new_pixel_width != old_pixel_width
467 || inhibit == 0 || inhibit == 2))
468 || (!inhibit_vertical
469 && (new_pixel_height != old_pixel_height
470 || inhibit == 0 || inhibit == 2))))
471 /* We are either allowed to change the frame size or the minimum
472 sizes request such a change. Do not care for fixing minimum
473 sizes here, we do that eventually when we're called from
474 change_frame_size. */
476 /* Make sure we respect fullheight and fullwidth. */
477 if (inhibit_horizontal)
478 new_text_width = old_text_width;
479 else if (inhibit_vertical)
480 new_text_height = old_text_height;
482 frame_size_history_add
483 (f, Qadjust_frame_size_2, new_text_width, new_text_height,
484 list2 (inhibit_horizontal ? Qt : Qnil,
485 inhibit_vertical ? Qt : Qnil));
487 x_set_window_size (f, 0, new_text_width, new_text_height, 1);
488 f->resized_p = true;
490 return;
492 #endif
494 if (new_text_width == old_text_width
495 && new_text_height == old_text_height
496 && new_windows_width == old_windows_width
497 && new_windows_height == old_windows_height
498 && new_pixel_width == old_pixel_width
499 && new_pixel_height == old_pixel_height
500 && new_cols == old_cols
501 && new_lines == old_lines)
502 /* No change. Sanitize window sizes and return. */
504 sanitize_window_sizes (Qt);
505 sanitize_window_sizes (Qnil);
507 return;
510 block_input ();
512 #ifdef MSDOS
513 /* We only can set screen dimensions to certain values supported by
514 our video hardware. Try to find the smallest size greater or
515 equal to the requested dimensions, while accounting for the fact
516 that the menu-bar lines are not counted in the frame height. */
517 int dos_new_lines = new_lines + FRAME_TOP_MARGIN (f);
518 dos_set_window_size (&dos_new_lines, &new_cols);
519 new_lines = dos_new_lines - FRAME_TOP_MARGIN (f);
520 #endif
522 if (new_windows_width != old_windows_width)
524 resize_frame_windows (f, new_windows_width, 1, 1);
526 /* MSDOS frames cannot PRETEND, as they change frame size by
527 manipulating video hardware. */
528 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
529 FrameCols (FRAME_TTY (f)) = new_cols;
531 #if defined (HAVE_WINDOW_SYSTEM) && ! defined (USE_GTK) && ! defined (HAVE_NS)
532 if (WINDOWP (f->tool_bar_window))
534 XWINDOW (f->tool_bar_window)->pixel_width = new_windows_width;
535 XWINDOW (f->tool_bar_window)->total_cols
536 = new_windows_width / unit_width;
538 #endif
540 else if (new_cols != old_cols)
541 call2 (Qwindow__pixel_to_total, frame, Qt);
543 if (new_windows_height != old_windows_height
544 /* When the top margin has changed we have to recalculate the top
545 edges of all windows. No such calculation is necessary for the
546 left edges. */
547 || WINDOW_TOP_PIXEL_EDGE (r) != FRAME_TOP_MARGIN_HEIGHT (f))
549 resize_frame_windows (f, new_windows_height, 0, 1);
551 /* MSDOS frames cannot PRETEND, as they change frame size by
552 manipulating video hardware. */
553 if ((FRAME_TERMCAP_P (f) && !pretend) || FRAME_MSDOS_P (f))
554 FrameRows (FRAME_TTY (f)) = new_lines + FRAME_TOP_MARGIN (f);
556 else if (new_lines != old_lines)
557 call2 (Qwindow__pixel_to_total, frame, Qnil);
559 frame_size_history_add
560 (f, Qadjust_frame_size_3, new_text_width, new_text_height,
561 list4 (make_number (old_pixel_width), make_number (old_pixel_height),
562 make_number (new_pixel_width), make_number (new_pixel_height)));
564 /* Assign new sizes. */
565 FRAME_TEXT_WIDTH (f) = new_text_width;
566 FRAME_TEXT_HEIGHT (f) = new_text_height;
567 FRAME_PIXEL_WIDTH (f) = new_pixel_width;
568 FRAME_PIXEL_HEIGHT (f) = new_pixel_height;
569 SET_FRAME_COLS (f, new_cols);
570 SET_FRAME_LINES (f, new_lines);
573 struct window *w = XWINDOW (FRAME_SELECTED_WINDOW (f));
574 int text_area_x, text_area_y, text_area_width, text_area_height;
576 window_box (w, TEXT_AREA, &text_area_x, &text_area_y, &text_area_width,
577 &text_area_height);
578 if (w->cursor.x >= text_area_x + text_area_width)
579 w->cursor.hpos = w->cursor.x = 0;
580 if (w->cursor.y >= text_area_y + text_area_height)
581 w->cursor.vpos = w->cursor.y = 0;
584 /* Sanitize window sizes. */
585 sanitize_window_sizes (Qt);
586 sanitize_window_sizes (Qnil);
588 adjust_frame_glyphs (f);
589 calculate_costs (f);
590 SET_FRAME_GARBAGED (f);
592 /* A frame was "resized" if one of its pixelsizes changed, even if its
593 X window wasn't resized at all. */
594 f->resized_p = (new_pixel_width != old_pixel_width
595 || new_pixel_height != old_pixel_height);
597 unblock_input ();
600 /* Allocate basically initialized frame. */
602 static struct frame *
603 allocate_frame (void)
605 return ALLOCATE_ZEROED_PSEUDOVECTOR (struct frame, face_cache, PVEC_FRAME);
608 struct frame *
609 make_frame (bool mini_p)
611 Lisp_Object frame;
612 struct frame *f;
613 struct window *rw, *mw;
614 Lisp_Object root_window;
615 Lisp_Object mini_window;
617 f = allocate_frame ();
618 XSETFRAME (frame, f);
620 #ifdef USE_GTK
621 /* Initialize Lisp data. Note that allocate_frame initializes all
622 Lisp data to nil, so do it only for slots which should not be nil. */
623 fset_tool_bar_position (f, Qtop);
624 #endif
626 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
627 non-Lisp data, so do it only for slots which should not be zero.
628 To avoid subtle bugs and for the sake of readability, it's better to
629 initialize enum members explicitly even if their values are zero. */
630 f->wants_modeline = true;
631 f->redisplay = true;
632 f->garbaged = true;
633 f->can_x_set_window_size = false;
634 f->after_make_frame = false;
635 f->inhibit_horizontal_resize = false;
636 f->inhibit_vertical_resize = false;
637 f->tool_bar_redisplayed = false;
638 f->tool_bar_resized = false;
639 f->column_width = 1; /* !FRAME_WINDOW_P value. */
640 f->line_height = 1; /* !FRAME_WINDOW_P value. */
641 #ifdef HAVE_WINDOW_SYSTEM
642 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
643 f->horizontal_scroll_bars = false;
644 f->want_fullscreen = FULLSCREEN_NONE;
645 #if ! defined (USE_GTK) && ! defined (HAVE_NS)
646 f->last_tool_bar_item = -1;
647 #endif
648 #endif
650 root_window = make_window ();
651 rw = XWINDOW (root_window);
652 if (mini_p)
654 mini_window = make_window ();
655 mw = XWINDOW (mini_window);
656 wset_next (rw, mini_window);
657 wset_prev (mw, root_window);
658 mw->mini = 1;
659 wset_frame (mw, frame);
660 fset_minibuffer_window (f, mini_window);
661 store_frame_param (f, Qminibuffer, Qt);
663 else
665 mini_window = Qnil;
666 wset_next (rw, Qnil);
667 fset_minibuffer_window (f, Qnil);
670 wset_frame (rw, frame);
672 /* 10 is arbitrary,
673 just so that there is "something there."
674 Correct size will be set up later with adjust_frame_size. */
676 SET_FRAME_COLS (f, 10);
677 SET_FRAME_LINES (f, 10);
678 SET_FRAME_WIDTH (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f));
679 SET_FRAME_HEIGHT (f, FRAME_LINES (f) * FRAME_LINE_HEIGHT (f));
681 rw->total_cols = 10;
682 rw->pixel_width = rw->total_cols * FRAME_COLUMN_WIDTH (f);
683 rw->total_lines = mini_p ? 9 : 10;
684 rw->pixel_height = rw->total_lines * FRAME_LINE_HEIGHT (f);
686 if (mini_p)
688 mw->top_line = rw->total_lines;
689 mw->pixel_top = rw->pixel_height;
690 mw->total_cols = rw->total_cols;
691 mw->pixel_width = rw->pixel_width;
692 mw->total_lines = 1;
693 mw->pixel_height = FRAME_LINE_HEIGHT (f);
696 /* Choose a buffer for the frame's root window. */
698 Lisp_Object buf = Fcurrent_buffer ();
700 /* If current buffer is hidden, try to find another one. */
701 if (BUFFER_HIDDEN_P (XBUFFER (buf)))
702 buf = other_buffer_safely (buf);
704 /* Use set_window_buffer, not Fset_window_buffer, and don't let
705 hooks be run by it. The reason is that the whole frame/window
706 arrangement is not yet fully initialized at this point. Windows
707 don't have the right size, glyph matrices aren't initialized
708 etc. Running Lisp functions at this point surely ends in a
709 SEGV. */
710 set_window_buffer (root_window, buf, 0, 0);
711 fset_buffer_list (f, list1 (buf));
714 if (mini_p)
716 set_window_buffer (mini_window,
717 (NILP (Vminibuffer_list)
718 ? get_minibuffer (0)
719 : Fcar (Vminibuffer_list)),
720 0, 0);
721 /* No horizontal scroll bars in minibuffers. */
722 wset_horizontal_scroll_bar (mw, Qnil);
725 fset_root_window (f, root_window);
726 fset_selected_window (f, root_window);
727 /* Make sure this window seems more recently used than
728 a newly-created, never-selected window. */
729 XWINDOW (f->selected_window)->use_time = ++window_select_count;
731 return f;
734 #ifdef HAVE_WINDOW_SYSTEM
735 /* Make a frame using a separate minibuffer window on another frame.
736 MINI_WINDOW is the minibuffer window to use. nil means use the
737 default (the global minibuffer). */
739 struct frame *
740 make_frame_without_minibuffer (Lisp_Object mini_window, KBOARD *kb,
741 Lisp_Object display)
743 struct frame *f;
745 if (!NILP (mini_window))
746 CHECK_LIVE_WINDOW (mini_window);
748 if (!NILP (mini_window)
749 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
750 error ("Frame and minibuffer must be on the same terminal");
752 /* Make a frame containing just a root window. */
753 f = make_frame (0);
755 if (NILP (mini_window))
757 /* Use default-minibuffer-frame if possible. */
758 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
759 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
761 Lisp_Object frame_dummy;
763 XSETFRAME (frame_dummy, f);
764 /* If there's no minibuffer frame to use, create one. */
765 kset_default_minibuffer_frame
766 (kb, call1 (intern ("make-initial-minibuffer-frame"), display));
769 mini_window
770 = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
773 fset_minibuffer_window (f, mini_window);
774 store_frame_param (f, Qminibuffer, mini_window);
776 /* Make the chosen minibuffer window display the proper minibuffer,
777 unless it is already showing a minibuffer. */
778 if (NILP (Fmemq (XWINDOW (mini_window)->contents, Vminibuffer_list)))
779 /* Use set_window_buffer instead of Fset_window_buffer (see
780 discussion of bug#11984, bug#12025, bug#12026). */
781 set_window_buffer (mini_window,
782 (NILP (Vminibuffer_list)
783 ? get_minibuffer (0)
784 : Fcar (Vminibuffer_list)), 0, 0);
785 return f;
788 /* Make a frame containing only a minibuffer window. */
790 struct frame *
791 make_minibuffer_frame (void)
793 /* First make a frame containing just a root window, no minibuffer. */
795 register struct frame *f = make_frame (0);
796 register Lisp_Object mini_window;
797 register Lisp_Object frame;
799 XSETFRAME (frame, f);
801 f->auto_raise = 0;
802 f->auto_lower = 0;
803 f->no_split = 1;
804 f->wants_modeline = 0;
806 /* Now label the root window as also being the minibuffer.
807 Avoid infinite looping on the window chain by marking next pointer
808 as nil. */
810 mini_window = f->root_window;
811 fset_minibuffer_window (f, mini_window);
812 store_frame_param (f, Qminibuffer, Qonly);
813 XWINDOW (mini_window)->mini = 1;
814 wset_next (XWINDOW (mini_window), Qnil);
815 wset_prev (XWINDOW (mini_window), Qnil);
816 wset_frame (XWINDOW (mini_window), frame);
818 /* Put the proper buffer in that window. */
820 /* Use set_window_buffer instead of Fset_window_buffer (see
821 discussion of bug#11984, bug#12025, bug#12026). */
822 set_window_buffer (mini_window,
823 (NILP (Vminibuffer_list)
824 ? get_minibuffer (0)
825 : Fcar (Vminibuffer_list)), 0, 0);
826 return f;
828 #endif /* HAVE_WINDOW_SYSTEM */
830 /* Construct a frame that refers to a terminal. */
832 static printmax_t tty_frame_count;
834 struct frame *
835 make_initial_frame (void)
837 struct frame *f;
838 struct terminal *terminal;
839 Lisp_Object frame;
841 eassert (initial_kboard);
843 /* The first call must initialize Vframe_list. */
844 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
845 Vframe_list = Qnil;
847 terminal = init_initial_terminal ();
849 f = make_frame (1);
850 XSETFRAME (frame, f);
852 Vframe_list = Fcons (frame, Vframe_list);
854 tty_frame_count = 1;
855 fset_name (f, build_pure_c_string ("F1"));
857 SET_FRAME_VISIBLE (f, 1);
859 f->output_method = terminal->type;
860 f->terminal = terminal;
861 f->terminal->reference_count++;
862 f->output_data.nothing = 0;
864 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
865 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
867 #ifdef HAVE_WINDOW_SYSTEM
868 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
869 f->horizontal_scroll_bars = false;
870 #endif
872 /* The default value of menu-bar-mode is t. */
873 set_menu_bar_lines (f, make_number (1), Qnil);
875 /* Allocate glyph matrices. */
876 adjust_frame_glyphs (f);
878 if (!noninteractive)
879 init_frame_faces (f);
881 last_nonminibuf_frame = f;
883 f->can_x_set_window_size = true;
884 f->after_make_frame = true;
886 return f;
890 static struct frame *
891 make_terminal_frame (struct terminal *terminal)
893 register struct frame *f;
894 Lisp_Object frame;
895 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
897 if (!terminal->name)
898 error ("Terminal is not live, can't create new frames on it");
900 f = make_frame (1);
902 XSETFRAME (frame, f);
903 Vframe_list = Fcons (frame, Vframe_list);
905 fset_name (f, make_formatted_string (name, "F%"pMd, ++tty_frame_count));
907 SET_FRAME_VISIBLE (f, 1);
909 f->terminal = terminal;
910 f->terminal->reference_count++;
911 #ifdef MSDOS
912 f->output_data.tty->display_info = &the_only_display_info;
913 if (!inhibit_window_system
914 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
915 || XFRAME (selected_frame)->output_method == output_msdos_raw))
916 f->output_method = output_msdos_raw;
917 else
918 f->output_method = output_termcap;
919 #else /* not MSDOS */
920 f->output_method = output_termcap;
921 create_tty_output (f);
922 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
923 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
924 #endif /* not MSDOS */
926 #ifdef HAVE_WINDOW_SYSTEM
927 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
928 f->horizontal_scroll_bars = false;
929 #endif
931 FRAME_MENU_BAR_LINES (f) = NILP (Vmenu_bar_mode) ? 0 : 1;
932 FRAME_LINES (f) = FRAME_LINES (f) - FRAME_MENU_BAR_LINES (f);
933 FRAME_MENU_BAR_HEIGHT (f) = FRAME_MENU_BAR_LINES (f) * FRAME_LINE_HEIGHT (f);
934 FRAME_TEXT_HEIGHT (f) = FRAME_TEXT_HEIGHT (f) - FRAME_MENU_BAR_HEIGHT (f);
936 /* Set the top frame to the newly created frame. */
937 if (FRAMEP (FRAME_TTY (f)->top_frame)
938 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
939 SET_FRAME_VISIBLE (XFRAME (FRAME_TTY (f)->top_frame), 2); /* obscured */
941 FRAME_TTY (f)->top_frame = frame;
943 if (!noninteractive)
944 init_frame_faces (f);
946 return f;
949 /* Get a suitable value for frame parameter PARAMETER for a newly
950 created frame, based on (1) the user-supplied frame parameter
951 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
953 static Lisp_Object
954 get_future_frame_param (Lisp_Object parameter,
955 Lisp_Object supplied_parms,
956 char *current_value)
958 Lisp_Object result;
960 result = Fassq (parameter, supplied_parms);
961 if (NILP (result))
962 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
963 if (NILP (result) && current_value != NULL)
964 result = build_string (current_value);
965 if (!NILP (result) && !STRINGP (result))
966 result = XCDR (result);
967 if (NILP (result) || !STRINGP (result))
968 result = Qnil;
970 return result;
973 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
974 1, 1, 0,
975 doc: /* Create an additional terminal frame, possibly on another terminal.
976 This function takes one argument, an alist specifying frame parameters.
978 You can create multiple frames on a single text terminal, but only one
979 of them (the selected terminal frame) is actually displayed.
981 In practice, generally you don't need to specify any parameters,
982 except when you want to create a new frame on another terminal.
983 In that case, the `tty' parameter specifies the device file to open,
984 and the `tty-type' parameter specifies the terminal type. Example:
986 (make-terminal-frame \\='((tty . "/dev/pts/5") (tty-type . "xterm")))
988 Note that changing the size of one terminal frame automatically
989 affects all frames on the same terminal device. */)
990 (Lisp_Object parms)
992 struct frame *f;
993 struct terminal *t = NULL;
994 Lisp_Object frame, tem;
995 struct frame *sf = SELECTED_FRAME ();
997 #ifdef MSDOS
998 if (sf->output_method != output_msdos_raw
999 && sf->output_method != output_termcap)
1000 emacs_abort ();
1001 #else /* not MSDOS */
1003 #ifdef WINDOWSNT /* This should work now! */
1004 if (sf->output_method != output_termcap)
1005 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
1006 #endif
1007 #endif /* not MSDOS */
1010 Lisp_Object terminal;
1012 terminal = Fassq (Qterminal, parms);
1013 if (CONSP (terminal))
1015 terminal = XCDR (terminal);
1016 t = decode_live_terminal (terminal);
1018 #ifdef MSDOS
1019 if (t && t != the_only_display_info.terminal)
1020 /* msdos.c assumes a single tty_display_info object. */
1021 error ("Multiple terminals are not supported on this platform");
1022 if (!t)
1023 t = the_only_display_info.terminal;
1024 #endif
1027 if (!t)
1029 char *name = 0, *type = 0;
1030 Lisp_Object tty, tty_type;
1031 USE_SAFE_ALLOCA;
1033 tty = get_future_frame_param
1034 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1035 ? FRAME_TTY (XFRAME (selected_frame))->name
1036 : NULL));
1037 if (!NILP (tty))
1038 SAFE_ALLOCA_STRING (name, tty);
1040 tty_type = get_future_frame_param
1041 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
1042 ? FRAME_TTY (XFRAME (selected_frame))->type
1043 : NULL));
1044 if (!NILP (tty_type))
1045 SAFE_ALLOCA_STRING (type, tty_type);
1047 t = init_tty (name, type, 0); /* Errors are not fatal. */
1048 SAFE_FREE ();
1051 f = make_terminal_frame (t);
1054 int width, height;
1055 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
1056 adjust_frame_size (f, width, height - FRAME_MENU_BAR_LINES (f),
1057 5, 0, Qterminal_frame);
1060 adjust_frame_glyphs (f);
1061 calculate_costs (f);
1062 XSETFRAME (frame, f);
1064 store_in_alist (&parms, Qtty_type, build_string (t->display_info.tty->type));
1065 store_in_alist (&parms, Qtty,
1066 (t->display_info.tty->name
1067 ? build_string (t->display_info.tty->name)
1068 : Qnil));
1069 Fmodify_frame_parameters (frame, parms);
1071 /* Make the frame face alist be frame-specific, so that each
1072 frame could change its face definitions independently. */
1073 fset_face_alist (f, Fcopy_alist (sf->face_alist));
1074 /* Simple Fcopy_alist isn't enough, because we need the contents of
1075 the vectors which are the CDRs of associations in face_alist to
1076 be copied as well. */
1077 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
1078 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
1080 f->can_x_set_window_size = true;
1081 f->after_make_frame = true;
1083 return frame;
1087 /* Perform the switch to frame FRAME.
1089 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
1090 FRAME1 as frame.
1092 If TRACK is non-zero and the frame that currently has the focus
1093 redirects its focus to the selected frame, redirect that focused
1094 frame's focus to FRAME instead.
1096 FOR_DELETION non-zero means that the selected frame is being
1097 deleted, which includes the possibility that the frame's terminal
1098 is dead.
1100 The value of NORECORD is passed as argument to Fselect_window. */
1102 Lisp_Object
1103 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
1105 struct frame *sf = SELECTED_FRAME ();
1107 /* If FRAME is a switch-frame event, extract the frame we should
1108 switch to. */
1109 if (CONSP (frame)
1110 && EQ (XCAR (frame), Qswitch_frame)
1111 && CONSP (XCDR (frame)))
1112 frame = XCAR (XCDR (frame));
1114 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
1115 a switch-frame event to arrive after a frame is no longer live,
1116 especially when deleting the initial frame during startup. */
1117 CHECK_FRAME (frame);
1118 if (! FRAME_LIVE_P (XFRAME (frame)))
1119 return Qnil;
1121 if (sf == XFRAME (frame))
1122 return frame;
1124 /* If a frame's focus has been redirected toward the currently
1125 selected frame, we should change the redirection to point to the
1126 newly selected frame. This means that if the focus is redirected
1127 from a minibufferless frame to a surrogate minibuffer frame, we
1128 can use `other-window' to switch between all the frames using
1129 that minibuffer frame, and the focus redirection will follow us
1130 around. */
1131 #if 0
1132 /* This is too greedy; it causes inappropriate focus redirection
1133 that's hard to get rid of. */
1134 if (track)
1136 Lisp_Object tail;
1138 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1140 Lisp_Object focus;
1142 if (!FRAMEP (XCAR (tail)))
1143 emacs_abort ();
1145 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
1147 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1148 Fredirect_frame_focus (XCAR (tail), frame);
1151 #else /* ! 0 */
1152 /* Instead, apply it only to the frame we're pointing to. */
1153 #ifdef HAVE_WINDOW_SYSTEM
1154 if (track && FRAME_WINDOW_P (XFRAME (frame)))
1156 Lisp_Object focus, xfocus;
1158 xfocus = x_get_focus_frame (XFRAME (frame));
1159 if (FRAMEP (xfocus))
1161 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
1162 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
1163 Fredirect_frame_focus (xfocus, frame);
1166 #endif /* HAVE_X_WINDOWS */
1167 #endif /* ! 0 */
1169 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
1170 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
1172 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
1174 struct frame *f = XFRAME (frame);
1175 struct tty_display_info *tty = FRAME_TTY (f);
1176 Lisp_Object top_frame = tty->top_frame;
1178 /* Don't mark the frame garbaged and/or obscured if we are
1179 switching to the frame that is already the top frame of that
1180 TTY. */
1181 if (!EQ (frame, top_frame))
1183 if (FRAMEP (top_frame))
1184 /* Mark previously displayed frame as now obscured. */
1185 SET_FRAME_VISIBLE (XFRAME (top_frame), 2);
1186 SET_FRAME_VISIBLE (f, 1);
1187 /* If the new TTY frame changed dimensions, we need to
1188 resync term.c's idea of the frame size with the new
1189 frame's data. */
1190 if (FRAME_COLS (f) != FrameCols (tty))
1191 FrameCols (tty) = FRAME_COLS (f);
1192 if (FRAME_TOTAL_LINES (f) != FrameRows (tty))
1193 FrameRows (tty) = FRAME_TOTAL_LINES (f);
1195 tty->top_frame = frame;
1198 selected_frame = frame;
1199 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
1200 last_nonminibuf_frame = XFRAME (selected_frame);
1202 Fselect_window (XFRAME (frame)->selected_window, norecord);
1204 /* We want to make sure that the next event generates a frame-switch
1205 event to the appropriate frame. This seems kludgy to me, but
1206 before you take it out, make sure that evaluating something like
1207 (select-window (frame-root-window (new-frame))) doesn't end up
1208 with your typing being interpreted in the new frame instead of
1209 the one you're actually typing in. */
1210 internal_last_event_frame = Qnil;
1212 return frame;
1215 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
1216 doc: /* Select FRAME.
1217 Subsequent editing commands apply to its selected window.
1218 Optional argument NORECORD means to neither change the order of
1219 recently selected windows nor the buffer list.
1221 The selection of FRAME lasts until the next time the user does
1222 something to select a different frame, or until the next time
1223 this function is called. If you are using a window system, the
1224 previously selected frame may be restored as the selected frame
1225 when returning to the command loop, because it still may have
1226 the window system's input focus. On a text terminal, the next
1227 redisplay will display FRAME.
1229 This function returns FRAME, or nil if FRAME has been deleted. */)
1230 (Lisp_Object frame, Lisp_Object norecord)
1232 return do_switch_frame (frame, 1, 0, norecord);
1235 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "^e",
1236 doc: /* Handle a switch-frame event EVENT.
1237 Switch-frame events are usually bound to this function.
1238 A switch-frame event tells Emacs that the window manager has requested
1239 that the user's events be directed to the frame mentioned in the event.
1240 This function selects the selected window of the frame of EVENT.
1242 If EVENT is frame object, handle it as if it were a switch-frame event
1243 to that frame. */)
1244 (Lisp_Object event)
1246 /* Preserve prefix arg that the command loop just cleared. */
1247 kset_prefix_arg (current_kboard, Vcurrent_prefix_arg);
1248 run_hook (Qmouse_leave_buffer_hook);
1249 /* `switch-frame' implies a focus in. */
1250 call1 (intern ("handle-focus-in"), event);
1251 return do_switch_frame (event, 0, 0, Qnil);
1254 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
1255 doc: /* Return the frame that is now selected. */)
1256 (void)
1258 return selected_frame;
1261 DEFUN ("frame-list", Fframe_list, Sframe_list,
1262 0, 0, 0,
1263 doc: /* Return a list of all live frames. */)
1264 (void)
1266 Lisp_Object frames;
1267 frames = Fcopy_sequence (Vframe_list);
1268 #ifdef HAVE_WINDOW_SYSTEM
1269 if (FRAMEP (tip_frame))
1270 frames = Fdelq (tip_frame, frames);
1271 #endif
1272 return frames;
1275 /* Return CANDIDATE if it can be used as 'other-than-FRAME' frame on the
1276 same tty (for tty frames) or among frames which uses FRAME's keyboard.
1277 If MINIBUF is nil, do not consider minibuffer-only candidate.
1278 If MINIBUF is `visible', do not consider an invisible candidate.
1279 If MINIBUF is a window, consider only its own frame and candidate now
1280 using that window as the minibuffer.
1281 If MINIBUF is 0, consider candidate if it is visible or iconified.
1282 Otherwise consider any candidate and return nil if CANDIDATE is not
1283 acceptable. */
1285 static Lisp_Object
1286 candidate_frame (Lisp_Object candidate, Lisp_Object frame, Lisp_Object minibuf)
1288 struct frame *c = XFRAME (candidate), *f = XFRAME (frame);
1290 if ((!FRAME_TERMCAP_P (c) && !FRAME_TERMCAP_P (f)
1291 && FRAME_KBOARD (c) == FRAME_KBOARD (f))
1292 || (FRAME_TERMCAP_P (c) && FRAME_TERMCAP_P (f)
1293 && FRAME_TTY (c) == FRAME_TTY (f)))
1295 if (NILP (minibuf))
1297 if (!FRAME_MINIBUF_ONLY_P (c))
1298 return candidate;
1300 else if (EQ (minibuf, Qvisible))
1302 if (FRAME_VISIBLE_P (c))
1303 return candidate;
1305 else if (WINDOWP (minibuf))
1307 if (EQ (FRAME_MINIBUF_WINDOW (c), minibuf)
1308 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), candidate)
1309 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1310 FRAME_FOCUS_FRAME (c)))
1311 return candidate;
1313 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1315 if (FRAME_VISIBLE_P (c) || FRAME_ICONIFIED_P (c))
1316 return candidate;
1318 else
1319 return candidate;
1321 return Qnil;
1324 /* Return the next frame in the frame list after FRAME. */
1326 static Lisp_Object
1327 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1329 Lisp_Object f, tail;
1330 int passed = 0;
1332 /* There must always be at least one frame in Vframe_list. */
1333 eassert (CONSP (Vframe_list));
1335 while (passed < 2)
1336 FOR_EACH_FRAME (tail, f)
1338 if (passed)
1340 f = candidate_frame (f, frame, minibuf);
1341 if (!NILP (f))
1342 return f;
1344 if (EQ (frame, f))
1345 passed++;
1347 return frame;
1350 /* Return the previous frame in the frame list before FRAME. */
1352 static Lisp_Object
1353 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1355 Lisp_Object f, tail, prev = Qnil;
1357 /* There must always be at least one frame in Vframe_list. */
1358 eassert (CONSP (Vframe_list));
1360 FOR_EACH_FRAME (tail, f)
1362 if (EQ (frame, f) && !NILP (prev))
1363 return prev;
1364 f = candidate_frame (f, frame, minibuf);
1365 if (!NILP (f))
1366 prev = f;
1369 /* We've scanned the entire list. */
1370 if (NILP (prev))
1371 /* We went through the whole frame list without finding a single
1372 acceptable frame. Return the original frame. */
1373 return frame;
1374 else
1375 /* There were no acceptable frames in the list before FRAME; otherwise,
1376 we would have returned directly from the loop. Since PREV is the last
1377 acceptable frame in the list, return it. */
1378 return prev;
1382 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1383 doc: /* Return the next frame in the frame list after FRAME.
1384 It considers only frames on the same terminal as FRAME.
1385 By default, skip minibuffer-only frames.
1386 If omitted, FRAME defaults to the selected frame.
1387 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1388 If MINIFRAME is a window, include only its own frame
1389 and any frame now using that window as the minibuffer.
1390 If MINIFRAME is `visible', include all visible frames.
1391 If MINIFRAME is 0, include all visible and iconified frames.
1392 Otherwise, include all frames. */)
1393 (Lisp_Object frame, Lisp_Object miniframe)
1395 if (NILP (frame))
1396 frame = selected_frame;
1397 CHECK_LIVE_FRAME (frame);
1398 return next_frame (frame, miniframe);
1401 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1402 doc: /* Return the previous frame in the frame list before FRAME.
1403 It considers only frames on the same terminal as FRAME.
1404 By default, skip minibuffer-only frames.
1405 If omitted, FRAME defaults to the selected frame.
1406 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1407 If MINIFRAME is a window, include only its own frame
1408 and any frame now using that window as the minibuffer.
1409 If MINIFRAME is `visible', include all visible frames.
1410 If MINIFRAME is 0, include all visible and iconified frames.
1411 Otherwise, include all frames. */)
1412 (Lisp_Object frame, Lisp_Object miniframe)
1414 if (NILP (frame))
1415 frame = selected_frame;
1416 CHECK_LIVE_FRAME (frame);
1417 return prev_frame (frame, miniframe);
1420 DEFUN ("last-nonminibuffer-frame", Flast_nonminibuf_frame,
1421 Slast_nonminibuf_frame, 0, 0, 0,
1422 doc: /* Return last non-minibuffer frame selected. */)
1423 (void)
1425 Lisp_Object frame = Qnil;
1427 if (last_nonminibuf_frame)
1428 XSETFRAME (frame, last_nonminibuf_frame);
1430 return frame;
1433 /* Return 1 if it is ok to delete frame F;
1434 0 if all frames aside from F are invisible.
1435 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1437 static int
1438 other_visible_frames (struct frame *f)
1440 Lisp_Object frames, this;
1442 FOR_EACH_FRAME (frames, this)
1444 if (f == XFRAME (this))
1445 continue;
1447 /* Verify that we can still talk to the frame's X window,
1448 and note any recent change in visibility. */
1449 #ifdef HAVE_X_WINDOWS
1450 if (FRAME_WINDOW_P (XFRAME (this)))
1451 x_sync (XFRAME (this));
1452 #endif
1454 if (FRAME_VISIBLE_P (XFRAME (this))
1455 || FRAME_ICONIFIED_P (XFRAME (this))
1456 /* Allow deleting the terminal frame when at least one X
1457 frame exists. */
1458 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1459 return 1;
1461 return 0;
1464 /* Make sure that minibuf_window doesn't refer to FRAME's minibuffer
1465 window. Preferably use the selected frame's minibuffer window
1466 instead. If the selected frame doesn't have one, get some other
1467 frame's minibuffer window. SELECT non-zero means select the new
1468 minibuffer window. */
1469 static void
1470 check_minibuf_window (Lisp_Object frame, int select)
1472 struct frame *f = decode_live_frame (frame);
1474 XSETFRAME (frame, f);
1476 if (WINDOWP (minibuf_window) && EQ (f->minibuffer_window, minibuf_window))
1478 Lisp_Object frames, this, window = make_number (0);
1480 if (!EQ (frame, selected_frame)
1481 && FRAME_HAS_MINIBUF_P (XFRAME (selected_frame)))
1482 window = FRAME_MINIBUF_WINDOW (XFRAME (selected_frame));
1483 else
1484 FOR_EACH_FRAME (frames, this)
1486 if (!EQ (this, frame) && FRAME_HAS_MINIBUF_P (XFRAME (this)))
1488 window = FRAME_MINIBUF_WINDOW (XFRAME (this));
1489 break;
1493 /* Don't abort if no window was found (Bug#15247). */
1494 if (WINDOWP (window))
1496 /* Use set_window_buffer instead of Fset_window_buffer (see
1497 discussion of bug#11984, bug#12025, bug#12026). */
1498 set_window_buffer (window, XWINDOW (minibuf_window)->contents, 0, 0);
1499 minibuf_window = window;
1501 /* SELECT non-zero usually means that FRAME's minibuffer
1502 window was selected; select the new one. */
1503 if (select)
1504 Fselect_window (minibuf_window, Qnil);
1510 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1511 unconditionally. x_connection_closed and delete_terminal use
1512 this. Any other value of FORCE implements the semantics
1513 described for Fdelete_frame. */
1514 Lisp_Object
1515 delete_frame (Lisp_Object frame, Lisp_Object force)
1517 struct frame *f = decode_any_frame (frame);
1518 struct frame *sf;
1519 struct kboard *kb;
1521 int minibuffer_selected, is_tooltip_frame;
1523 if (! FRAME_LIVE_P (f))
1524 return Qnil;
1526 if (NILP (force) && !other_visible_frames (f))
1527 error ("Attempt to delete the sole visible or iconified frame");
1529 /* x_connection_closed must have set FORCE to `noelisp' in order
1530 to delete the last frame, if it is gone. */
1531 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1532 error ("Attempt to delete the only frame");
1534 XSETFRAME (frame, f);
1536 /* Does this frame have a minibuffer, and is it the surrogate
1537 minibuffer for any other frame? */
1538 if (FRAME_HAS_MINIBUF_P (f))
1540 Lisp_Object frames, this;
1542 FOR_EACH_FRAME (frames, this)
1544 Lisp_Object fminiw;
1546 if (EQ (this, frame))
1547 continue;
1549 fminiw = FRAME_MINIBUF_WINDOW (XFRAME (this));
1551 if (WINDOWP (fminiw) && EQ (frame, WINDOW_FRAME (XWINDOW (fminiw))))
1553 /* If we MUST delete this frame, delete the other first.
1554 But do this only if FORCE equals `noelisp'. */
1555 if (EQ (force, Qnoelisp))
1556 delete_frame (this, Qnoelisp);
1557 else
1558 error ("Attempt to delete a surrogate minibuffer frame");
1563 is_tooltip_frame = !NILP (Fframe_parameter (frame, Qtooltip));
1565 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1566 frame is a tooltip. FORCE is set to `noelisp' when handling
1567 a disconnect from the terminal, so we don't dare call Lisp
1568 code. */
1569 if (NILP (Vrun_hooks) || is_tooltip_frame)
1571 else if (EQ (force, Qnoelisp))
1572 pending_funcalls
1573 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1574 pending_funcalls);
1575 else
1577 #ifdef HAVE_X_WINDOWS
1578 /* Also, save clipboard to the clipboard manager. */
1579 x_clipboard_manager_save_frame (frame);
1580 #endif
1582 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1585 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1586 if (! FRAME_LIVE_P (f))
1587 return Qnil;
1589 /* At this point, we are committed to deleting the frame.
1590 There is no more chance for errors to prevent it. */
1592 minibuffer_selected = EQ (minibuf_window, selected_window);
1593 sf = SELECTED_FRAME ();
1594 /* Don't let the frame remain selected. */
1595 if (f == sf)
1597 Lisp_Object tail;
1598 Lisp_Object frame1 = Qnil;
1600 /* Look for another visible frame on the same terminal.
1601 Do not call next_frame here because it may loop forever.
1602 See http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15025. */
1603 FOR_EACH_FRAME (tail, frame1)
1604 if (!EQ (frame, frame1)
1605 && (FRAME_TERMINAL (XFRAME (frame))
1606 == FRAME_TERMINAL (XFRAME (frame1)))
1607 && FRAME_VISIBLE_P (XFRAME (frame1)))
1608 break;
1610 /* If there is none, find *some* other frame. */
1611 if (NILP (frame1) || EQ (frame1, frame))
1613 FOR_EACH_FRAME (tail, frame1)
1615 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1617 /* Do not change a text terminal's top-frame. */
1618 struct frame *f1 = XFRAME (frame1);
1619 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1621 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1622 if (!EQ (top_frame, frame))
1623 frame1 = top_frame;
1625 break;
1629 #ifdef NS_IMPL_COCOA
1630 else
1631 /* Under NS, there is no system mechanism for choosing a new
1632 window to get focus -- it is left to application code.
1633 So the portion of THIS application interfacing with NS
1634 needs to know about it. We call Fraise_frame, but the
1635 purpose is really to transfer focus. */
1636 Fraise_frame (frame1);
1637 #endif
1639 do_switch_frame (frame1, 0, 1, Qnil);
1640 sf = SELECTED_FRAME ();
1643 /* Don't allow minibuf_window to remain on a deleted frame. */
1644 check_minibuf_window (frame, minibuffer_selected);
1646 /* Don't let echo_area_window to remain on a deleted frame. */
1647 if (EQ (f->minibuffer_window, echo_area_window))
1648 echo_area_window = sf->minibuffer_window;
1650 /* Clear any X selections for this frame. */
1651 #ifdef HAVE_X_WINDOWS
1652 if (FRAME_X_P (f))
1653 x_clear_frame_selections (f);
1654 #endif
1656 /* Free glyphs.
1657 This function must be called before the window tree of the
1658 frame is deleted because windows contain dynamically allocated
1659 memory. */
1660 free_glyphs (f);
1662 #ifdef HAVE_WINDOW_SYSTEM
1663 /* Give chance to each font driver to free a frame specific data. */
1664 font_update_drivers (f, Qnil);
1665 #endif
1667 /* Mark all the windows that used to be on FRAME as deleted, and then
1668 remove the reference to them. */
1669 delete_all_child_windows (f->root_window);
1670 fset_root_window (f, Qnil);
1672 Vframe_list = Fdelq (frame, Vframe_list);
1673 SET_FRAME_VISIBLE (f, 0);
1675 /* Allow the vector of menu bar contents to be freed in the next
1676 garbage collection. The frame object itself may not be garbage
1677 collected until much later, because recent_keys and other data
1678 structures can still refer to it. */
1679 fset_menu_bar_vector (f, Qnil);
1681 /* If FRAME's buffer lists contains killed
1682 buffers, this helps GC to reclaim them. */
1683 fset_buffer_list (f, Qnil);
1684 fset_buried_buffer_list (f, Qnil);
1686 free_font_driver_list (f);
1687 #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI)
1688 xfree (f->namebuf);
1689 #endif
1690 xfree (f->decode_mode_spec_buffer);
1691 xfree (FRAME_INSERT_COST (f));
1692 xfree (FRAME_DELETEN_COST (f));
1693 xfree (FRAME_INSERTN_COST (f));
1694 xfree (FRAME_DELETE_COST (f));
1696 /* Since some events are handled at the interrupt level, we may get
1697 an event for f at any time; if we zero out the frame's terminal
1698 now, then we may trip up the event-handling code. Instead, we'll
1699 promise that the terminal of the frame must be valid until we
1700 have called the window-system-dependent frame destruction
1701 routine. */
1705 struct terminal *terminal;
1706 block_input ();
1707 if (FRAME_TERMINAL (f)->delete_frame_hook)
1708 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1709 terminal = FRAME_TERMINAL (f);
1710 f->output_data.nothing = 0;
1711 f->terminal = 0; /* Now the frame is dead. */
1712 unblock_input ();
1714 /* If needed, delete the terminal that this frame was on.
1715 (This must be done after the frame is killed.) */
1716 terminal->reference_count--;
1717 #ifdef USE_GTK
1718 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1719 bug.
1720 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1721 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1722 terminal->reference_count = 1;
1723 #endif /* USE_GTK */
1724 if (terminal->reference_count == 0)
1726 Lisp_Object tmp;
1727 XSETTERMINAL (tmp, terminal);
1729 kb = NULL;
1730 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1732 else
1733 kb = terminal->kboard;
1736 /* If we've deleted the last_nonminibuf_frame, then try to find
1737 another one. */
1738 if (f == last_nonminibuf_frame)
1740 Lisp_Object frames, this;
1742 last_nonminibuf_frame = 0;
1744 FOR_EACH_FRAME (frames, this)
1746 f = XFRAME (this);
1747 if (!FRAME_MINIBUF_ONLY_P (f))
1749 last_nonminibuf_frame = f;
1750 break;
1755 /* If there's no other frame on the same kboard, get out of
1756 single-kboard state if we're in it for this kboard. */
1757 if (kb != NULL)
1759 Lisp_Object frames, this;
1760 /* Some frame we found on the same kboard, or nil if there are none. */
1761 Lisp_Object frame_on_same_kboard = Qnil;
1763 FOR_EACH_FRAME (frames, this)
1764 if (kb == FRAME_KBOARD (XFRAME (this)))
1765 frame_on_same_kboard = this;
1767 if (NILP (frame_on_same_kboard))
1768 not_single_kboard_state (kb);
1772 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1773 find another one. Prefer minibuffer-only frames, but also notice
1774 frames with other windows. */
1775 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1777 Lisp_Object frames, this;
1779 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1780 Lisp_Object frame_with_minibuf = Qnil;
1781 /* Some frame we found on the same kboard, or nil if there are none. */
1782 Lisp_Object frame_on_same_kboard = Qnil;
1784 FOR_EACH_FRAME (frames, this)
1786 struct frame *f1 = XFRAME (this);
1788 /* Consider only frames on the same kboard
1789 and only those with minibuffers. */
1790 if (kb == FRAME_KBOARD (f1)
1791 && FRAME_HAS_MINIBUF_P (f1))
1793 frame_with_minibuf = this;
1794 if (FRAME_MINIBUF_ONLY_P (f1))
1795 break;
1798 if (kb == FRAME_KBOARD (f1))
1799 frame_on_same_kboard = this;
1802 if (!NILP (frame_on_same_kboard))
1804 /* We know that there must be some frame with a minibuffer out
1805 there. If this were not true, all of the frames present
1806 would have to be minibufferless, which implies that at some
1807 point their minibuffer frames must have been deleted, but
1808 that is prohibited at the top; you can't delete surrogate
1809 minibuffer frames. */
1810 if (NILP (frame_with_minibuf))
1811 emacs_abort ();
1813 kset_default_minibuffer_frame (kb, frame_with_minibuf);
1815 else
1816 /* No frames left on this kboard--say no minibuffer either. */
1817 kset_default_minibuffer_frame (kb, Qnil);
1820 /* Cause frame titles to update--necessary if we now have just one frame. */
1821 if (!is_tooltip_frame)
1822 update_mode_lines = 15;
1824 return Qnil;
1827 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1828 doc: /* Delete FRAME, permanently eliminating it from use.
1829 FRAME must be a live frame and defaults to the selected one.
1831 A frame may not be deleted if its minibuffer serves as surrogate
1832 minibuffer for another frame. Normally, you may not delete a frame if
1833 all other frames are invisible, but if the second optional argument
1834 FORCE is non-nil, you may do so.
1836 This function runs `delete-frame-functions' before actually
1837 deleting the frame, unless the frame is a tooltip.
1838 The functions are run with one argument, the frame to be deleted. */)
1839 (Lisp_Object frame, Lisp_Object force)
1841 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1845 /* Return mouse position in character cell units. */
1847 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1848 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1849 The position is given in canonical character cells, where (0, 0) is the
1850 upper-left corner of the frame, X is the horizontal offset, and Y is the
1851 vertical offset, measured in units of the frame's default character size.
1852 If Emacs is running on a mouseless terminal or hasn't been programmed
1853 to read the mouse position, it returns the selected frame for FRAME
1854 and nil for X and Y.
1855 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1856 passing the normal return value to that function as an argument,
1857 and returns whatever that function returns. */)
1858 (void)
1860 struct frame *f;
1861 Lisp_Object lispy_dummy;
1862 Lisp_Object x, y, retval;
1864 f = SELECTED_FRAME ();
1865 x = y = Qnil;
1867 /* It's okay for the hook to refrain from storing anything. */
1868 if (FRAME_TERMINAL (f)->mouse_position_hook)
1870 enum scroll_bar_part party_dummy;
1871 Time time_dummy;
1872 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1873 &lispy_dummy, &party_dummy,
1874 &x, &y,
1875 &time_dummy);
1878 if (! NILP (x))
1880 int col = XINT (x);
1881 int row = XINT (y);
1882 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1883 XSETINT (x, col);
1884 XSETINT (y, row);
1886 XSETFRAME (lispy_dummy, f);
1887 retval = Fcons (lispy_dummy, Fcons (x, y));
1888 if (!NILP (Vmouse_position_function))
1889 retval = call1 (Vmouse_position_function, retval);
1890 return retval;
1893 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1894 Smouse_pixel_position, 0, 0, 0,
1895 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1896 The position is given in pixel units, where (0, 0) is the
1897 upper-left corner of the frame, X is the horizontal offset, and Y is
1898 the vertical offset.
1899 If Emacs is running on a mouseless terminal or hasn't been programmed
1900 to read the mouse position, it returns the selected frame for FRAME
1901 and nil for X and Y. */)
1902 (void)
1904 struct frame *f;
1905 Lisp_Object lispy_dummy;
1906 Lisp_Object x, y, retval;
1908 f = SELECTED_FRAME ();
1909 x = y = Qnil;
1911 /* It's okay for the hook to refrain from storing anything. */
1912 if (FRAME_TERMINAL (f)->mouse_position_hook)
1914 enum scroll_bar_part party_dummy;
1915 Time time_dummy;
1916 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1917 &lispy_dummy, &party_dummy,
1918 &x, &y,
1919 &time_dummy);
1922 XSETFRAME (lispy_dummy, f);
1923 retval = Fcons (lispy_dummy, Fcons (x, y));
1924 if (!NILP (Vmouse_position_function))
1925 retval = call1 (Vmouse_position_function, retval);
1926 return retval;
1929 #ifdef HAVE_WINDOW_SYSTEM
1931 /* On frame F, convert character coordinates X and Y to pixel
1932 coordinates *PIX_X and *PIX_Y. */
1934 static void
1935 frame_char_to_pixel_position (struct frame *f, int x, int y,
1936 int *pix_x, int *pix_y)
1938 *pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2;
1939 *pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2;
1941 if (*pix_x < 0)
1942 *pix_x = 0;
1943 if (*pix_x > FRAME_PIXEL_WIDTH (f))
1944 *pix_x = FRAME_PIXEL_WIDTH (f);
1946 if (*pix_y < 0)
1947 *pix_y = 0;
1948 if (*pix_y > FRAME_PIXEL_HEIGHT (f))
1949 *pix_y = FRAME_PIXEL_HEIGHT (f);
1952 /* On frame F, reposition mouse pointer to character coordinates X and Y. */
1954 static void
1955 frame_set_mouse_position (struct frame *f, int x, int y)
1957 int pix_x, pix_y;
1959 frame_char_to_pixel_position (f, x, y, &pix_x, &pix_y);
1960 frame_set_mouse_pixel_position (f, pix_x, pix_y);
1963 #endif /* HAVE_WINDOW_SYSTEM */
1965 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1966 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1967 Coordinates are relative to the frame, not a window,
1968 so the coordinates of the top left character in the frame
1969 may be nonzero due to left-hand scroll bars or the menu bar.
1971 The position is given in canonical character cells, where (0, 0) is
1972 the upper-left corner of the frame, X is the horizontal offset, and
1973 Y is the vertical offset, measured in units of the frame's default
1974 character size.
1976 This function is a no-op for an X frame that is not visible.
1977 If you have just created a frame, you must wait for it to become visible
1978 before calling this function on it, like this.
1979 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1980 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1982 CHECK_LIVE_FRAME (frame);
1983 CHECK_TYPE_RANGED_INTEGER (int, x);
1984 CHECK_TYPE_RANGED_INTEGER (int, y);
1986 /* I think this should be done with a hook. */
1987 #ifdef HAVE_WINDOW_SYSTEM
1988 if (FRAME_WINDOW_P (XFRAME (frame)))
1989 /* Warping the mouse will cause enternotify and focus events. */
1990 frame_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1991 #else
1992 #if defined (MSDOS)
1993 if (FRAME_MSDOS_P (XFRAME (frame)))
1995 Fselect_frame (frame, Qnil);
1996 mouse_moveto (XINT (x), XINT (y));
1998 #else
1999 #ifdef HAVE_GPM
2001 Fselect_frame (frame, Qnil);
2002 term_mouse_moveto (XINT (x), XINT (y));
2004 #endif
2005 #endif
2006 #endif
2008 return Qnil;
2011 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
2012 Sset_mouse_pixel_position, 3, 3, 0,
2013 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
2014 The position is given in pixels, where (0, 0) is the upper-left corner
2015 of the frame, X is the horizontal offset, and Y is the vertical offset.
2017 Note, this is a no-op for an X frame that is not visible.
2018 If you have just created a frame, you must wait for it to become visible
2019 before calling this function on it, like this.
2020 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
2021 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
2023 CHECK_LIVE_FRAME (frame);
2024 CHECK_TYPE_RANGED_INTEGER (int, x);
2025 CHECK_TYPE_RANGED_INTEGER (int, y);
2027 /* I think this should be done with a hook. */
2028 #ifdef HAVE_WINDOW_SYSTEM
2029 if (FRAME_WINDOW_P (XFRAME (frame)))
2030 /* Warping the mouse will cause enternotify and focus events. */
2031 frame_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
2032 #else
2033 #if defined (MSDOS)
2034 if (FRAME_MSDOS_P (XFRAME (frame)))
2036 Fselect_frame (frame, Qnil);
2037 mouse_moveto (XINT (x), XINT (y));
2039 #else
2040 #ifdef HAVE_GPM
2042 Fselect_frame (frame, Qnil);
2043 term_mouse_moveto (XINT (x), XINT (y));
2045 #endif
2046 #endif
2047 #endif
2049 return Qnil;
2052 static void make_frame_visible_1 (Lisp_Object);
2054 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
2055 0, 1, "",
2056 doc: /* Make the frame FRAME visible (assuming it is an X window).
2057 If omitted, FRAME defaults to the currently selected frame. */)
2058 (Lisp_Object frame)
2060 struct frame *f = decode_live_frame (frame);
2062 /* I think this should be done with a hook. */
2063 #ifdef HAVE_WINDOW_SYSTEM
2064 if (FRAME_WINDOW_P (f))
2065 x_make_frame_visible (f);
2066 #endif
2068 make_frame_visible_1 (f->root_window);
2070 /* Make menu bar update for the Buffers and Frames menus. */
2071 /* windows_or_buffers_changed = 15; FIXME: Why? */
2073 XSETFRAME (frame, f);
2074 return frame;
2077 /* Update the display_time slot of the buffers shown in WINDOW
2078 and all its descendants. */
2080 static void
2081 make_frame_visible_1 (Lisp_Object window)
2083 struct window *w;
2085 for (; !NILP (window); window = w->next)
2087 w = XWINDOW (window);
2088 if (WINDOWP (w->contents))
2089 make_frame_visible_1 (w->contents);
2090 else
2091 bset_display_time (XBUFFER (w->contents), Fcurrent_time ());
2095 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
2096 0, 2, "",
2097 doc: /* Make the frame FRAME invisible.
2098 If omitted, FRAME defaults to the currently selected frame.
2099 On graphical displays, invisible frames are not updated and are
2100 usually not displayed at all, even in a window system's \"taskbar\".
2102 Normally you may not make FRAME invisible if all other frames are invisible,
2103 but if the second optional argument FORCE is non-nil, you may do so.
2105 This function has no effect on text terminal frames. Such frames are
2106 always considered visible, whether or not they are currently being
2107 displayed in the terminal. */)
2108 (Lisp_Object frame, Lisp_Object force)
2110 struct frame *f = decode_live_frame (frame);
2112 if (NILP (force) && !other_visible_frames (f))
2113 error ("Attempt to make invisible the sole visible or iconified frame");
2115 /* Don't allow minibuf_window to remain on an invisible frame. */
2116 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2118 /* I think this should be done with a hook. */
2119 #ifdef HAVE_WINDOW_SYSTEM
2120 if (FRAME_WINDOW_P (f))
2121 x_make_frame_invisible (f);
2122 #endif
2124 /* Make menu bar update for the Buffers and Frames menus. */
2125 windows_or_buffers_changed = 16;
2127 return Qnil;
2130 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
2131 0, 1, "",
2132 doc: /* Make the frame FRAME into an icon.
2133 If omitted, FRAME defaults to the currently selected frame. */)
2134 (Lisp_Object frame)
2136 struct frame *f = decode_live_frame (frame);
2138 /* Don't allow minibuf_window to remain on an iconified frame. */
2139 check_minibuf_window (frame, EQ (minibuf_window, selected_window));
2141 /* I think this should be done with a hook. */
2142 if (FRAME_WINDOW_P (f))
2144 #ifdef HAVE_WINDOW_SYSTEM
2145 x_iconify_frame (f);
2146 #endif
2149 /* Make menu bar update for the Buffers and Frames menus. */
2150 windows_or_buffers_changed = 17;
2152 return Qnil;
2155 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
2156 1, 1, 0,
2157 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
2158 Return the symbol `icon' if FRAME is iconified or \"minimized\".
2159 Return nil if FRAME was made invisible, via `make-frame-invisible'.
2160 On graphical displays, invisible frames are not updated and are
2161 usually not displayed at all, even in a window system's \"taskbar\".
2163 If FRAME is a text terminal frame, this always returns t.
2164 Such frames are always considered visible, whether or not they are
2165 currently being displayed on the terminal. */)
2166 (Lisp_Object frame)
2168 CHECK_LIVE_FRAME (frame);
2170 if (FRAME_VISIBLE_P (XFRAME (frame)))
2171 return Qt;
2172 if (FRAME_ICONIFIED_P (XFRAME (frame)))
2173 return Qicon;
2174 return Qnil;
2177 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
2178 0, 0, 0,
2179 doc: /* Return a list of all frames now \"visible\" (being updated). */)
2180 (void)
2182 Lisp_Object tail, frame, value = Qnil;
2184 FOR_EACH_FRAME (tail, frame)
2185 if (FRAME_VISIBLE_P (XFRAME (frame)))
2186 value = Fcons (frame, value);
2188 return value;
2192 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
2193 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
2194 If FRAME is invisible or iconified, make it visible.
2195 If you don't specify a frame, the selected frame is used.
2196 If Emacs is displaying on an ordinary terminal or some other device which
2197 doesn't support multiple overlapping frames, this function selects FRAME. */)
2198 (Lisp_Object frame)
2200 struct frame *f = decode_live_frame (frame);
2202 XSETFRAME (frame, f);
2204 if (FRAME_TERMCAP_P (f))
2205 /* On a text terminal select FRAME. */
2206 Fselect_frame (frame, Qnil);
2207 else
2208 /* Do like the documentation says. */
2209 Fmake_frame_visible (frame);
2211 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2212 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2214 return Qnil;
2217 /* Should we have a corresponding function called Flower_Power? */
2218 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2219 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2220 If you don't specify a frame, the selected frame is used.
2221 If Emacs is displaying on an ordinary terminal or some other device which
2222 doesn't support multiple overlapping frames, this function does nothing. */)
2223 (Lisp_Object frame)
2225 struct frame *f = decode_live_frame (frame);
2227 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2228 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2230 return Qnil;
2234 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2235 1, 2, 0,
2236 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2237 In other words, switch-frame events caused by events in FRAME will
2238 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2239 FOCUS-FRAME after reading an event typed at FRAME.
2241 If FOCUS-FRAME is nil, any existing redirection is canceled, and the
2242 frame again receives its own keystrokes.
2244 Focus redirection is useful for temporarily redirecting keystrokes to
2245 a surrogate minibuffer frame when a frame doesn't have its own
2246 minibuffer window.
2248 A frame's focus redirection can be changed by `select-frame'. If frame
2249 FOO is selected, and then a different frame BAR is selected, any
2250 frames redirecting their focus to FOO are shifted to redirect their
2251 focus to BAR. This allows focus redirection to work properly when the
2252 user switches from one frame to another using `select-window'.
2254 This means that a frame whose focus is redirected to itself is treated
2255 differently from a frame whose focus is redirected to nil; the former
2256 is affected by `select-frame', while the latter is not.
2258 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2259 (Lisp_Object frame, Lisp_Object focus_frame)
2261 /* Note that we don't check for a live frame here. It's reasonable
2262 to redirect the focus of a frame you're about to delete, if you
2263 know what other frame should receive those keystrokes. */
2264 struct frame *f = decode_any_frame (frame);
2266 if (! NILP (focus_frame))
2267 CHECK_LIVE_FRAME (focus_frame);
2269 fset_focus_frame (f, focus_frame);
2271 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2272 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2274 return Qnil;
2278 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 0, 1, 0,
2279 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2280 If FRAME is omitted or nil, the selected frame is used.
2281 Return nil if FRAME's focus is not redirected.
2282 See `redirect-frame-focus'. */)
2283 (Lisp_Object frame)
2285 return FRAME_FOCUS_FRAME (decode_live_frame (frame));
2288 DEFUN ("x-focus-frame", Fx_focus_frame, Sx_focus_frame, 1, 1, 0,
2289 doc: /* Set the input focus to FRAME.
2290 FRAME nil means use the selected frame.
2291 If there is no window system support, this function does nothing. */)
2292 (Lisp_Object frame)
2294 #ifdef HAVE_WINDOW_SYSTEM
2295 x_focus_frame (decode_window_system_frame (frame));
2296 #endif
2297 return Qnil;
2300 DEFUN ("frame-after-make-frame",
2301 Fframe_after_make_frame,
2302 Sframe_after_make_frame, 2, 2, 0,
2303 doc: /* Mark FRAME as made.
2304 FRAME nil means use the selected frame. Second argument MADE non-nil
2305 means functions on `window-configuration-change-hook' are called
2306 whenever the window configuration of FRAME changes. MADE nil means
2307 these functions are not called.
2309 This function is currently called by `make-frame' only and should be
2310 otherwise used with utter care to avoid that running functions on
2311 `window-configuration-change-hook' is impeded forever. */)
2312 (Lisp_Object frame, Lisp_Object made)
2314 struct frame *f = decode_live_frame (frame);
2315 f->after_make_frame = !NILP (made);
2316 f->inhibit_horizontal_resize = false;
2317 f->inhibit_vertical_resize = false;
2318 return made;
2322 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2324 void
2325 frames_discard_buffer (Lisp_Object buffer)
2327 Lisp_Object frame, tail;
2329 FOR_EACH_FRAME (tail, frame)
2331 fset_buffer_list
2332 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buffer_list));
2333 fset_buried_buffer_list
2334 (XFRAME (frame), Fdelq (buffer, XFRAME (frame)->buried_buffer_list));
2338 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2339 If the alist already has an element for PROP, we change it. */
2341 void
2342 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2344 register Lisp_Object tem;
2346 tem = Fassq (prop, *alistptr);
2347 if (EQ (tem, Qnil))
2348 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2349 else
2350 Fsetcdr (tem, val);
2353 static int
2354 frame_name_fnn_p (char *str, ptrdiff_t len)
2356 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2358 char *p = str + 2;
2359 while ('0' <= *p && *p <= '9')
2360 p++;
2361 if (p == str + len)
2362 return 1;
2364 return 0;
2367 /* Set the name of the terminal frame. Also used by MSDOS frames.
2368 Modeled after x_set_name which is used for WINDOW frames. */
2370 static void
2371 set_term_frame_name (struct frame *f, Lisp_Object name)
2373 f->explicit_name = ! NILP (name);
2375 /* If NAME is nil, set the name to F<num>. */
2376 if (NILP (name))
2378 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2380 /* Check for no change needed in this very common case
2381 before we do any consing. */
2382 if (frame_name_fnn_p (SSDATA (f->name), SBYTES (f->name)))
2383 return;
2385 name = make_formatted_string (namebuf, "F%"pMd, ++tty_frame_count);
2387 else
2389 CHECK_STRING (name);
2391 /* Don't change the name if it's already NAME. */
2392 if (! NILP (Fstring_equal (name, f->name)))
2393 return;
2395 /* Don't allow the user to set the frame name to F<num>, so it
2396 doesn't clash with the names we generate for terminal frames. */
2397 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2398 error ("Frame names of the form F<num> are usurped by Emacs");
2401 fset_name (f, name);
2402 update_mode_lines = 16;
2405 void
2406 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2408 register Lisp_Object old_alist_elt;
2410 if (EQ (prop, Qminibuffer))
2412 if (WINDOWP (val))
2414 if (!MINI_WINDOW_P (XWINDOW (val)))
2415 error ("The `minibuffer' parameter does not specify a valid minibuffer window");
2416 else if (FRAME_MINIBUF_ONLY_P (f))
2418 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2419 val = Qonly;
2420 else
2421 error ("Can't change the minibuffer window of a minibuffer-only frame");
2423 else if (FRAME_HAS_MINIBUF_P (f))
2425 if (EQ (val, FRAME_MINIBUF_WINDOW (f)))
2426 val = Qt;
2427 else
2428 error ("Can't change the minibuffer window of a frame with its own minibuffer");
2430 else
2431 /* Store the chosen minibuffer window. */
2432 fset_minibuffer_window (f, val);
2434 else
2436 Lisp_Object old_val = Fcdr (Fassq (Qminibuffer, f->param_alist));
2438 if (!NILP (old_val))
2440 if (WINDOWP (old_val) && NILP (val))
2441 /* Don't change the value for a minibuffer-less frame if
2442 only nil was specified as new value. */
2443 val = old_val;
2444 else if (!EQ (old_val, val))
2445 error ("Can't change the `minibuffer' parameter of this frame");
2450 /* The buffer-list parameters are stored in a special place and not
2451 in the alist. All buffers must be live. */
2452 if (EQ (prop, Qbuffer_list))
2454 Lisp_Object list = Qnil;
2455 for (; CONSP (val); val = XCDR (val))
2456 if (!NILP (Fbuffer_live_p (XCAR (val))))
2457 list = Fcons (XCAR (val), list);
2458 fset_buffer_list (f, Fnreverse (list));
2459 return;
2461 if (EQ (prop, Qburied_buffer_list))
2463 Lisp_Object list = Qnil;
2464 for (; CONSP (val); val = XCDR (val))
2465 if (!NILP (Fbuffer_live_p (XCAR (val))))
2466 list = Fcons (XCAR (val), list);
2467 fset_buried_buffer_list (f, Fnreverse (list));
2468 return;
2471 /* If PROP is a symbol which is supposed to have frame-local values,
2472 and it is set up based on this frame, switch to the global
2473 binding. That way, we can create or alter the frame-local binding
2474 without messing up the symbol's status. */
2475 if (SYMBOLP (prop))
2477 struct Lisp_Symbol *sym = XSYMBOL (prop);
2478 start:
2479 switch (sym->redirect)
2481 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2482 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2483 case SYMBOL_LOCALIZED:
2484 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2485 if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f)
2486 swap_in_global_binding (sym);
2487 break;
2489 default: emacs_abort ();
2493 /* The tty color needed to be set before the frame's parameter
2494 alist was updated with the new value. This is not true any more,
2495 but we still do this test early on. */
2496 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2497 && f == FRAME_TTY (f)->previous_frame)
2498 /* Force redisplay of this tty. */
2499 FRAME_TTY (f)->previous_frame = NULL;
2501 /* Update the frame parameter alist. */
2502 old_alist_elt = Fassq (prop, f->param_alist);
2503 if (EQ (old_alist_elt, Qnil))
2504 fset_param_alist (f, Fcons (Fcons (prop, val), f->param_alist));
2505 else
2506 Fsetcdr (old_alist_elt, val);
2508 /* Update some other special parameters in their special places
2509 in addition to the alist. */
2511 if (EQ (prop, Qbuffer_predicate))
2512 fset_buffer_predicate (f, val);
2514 if (! FRAME_WINDOW_P (f))
2516 if (EQ (prop, Qmenu_bar_lines))
2517 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2518 else if (EQ (prop, Qname))
2519 set_term_frame_name (f, val);
2523 /* Return color matches UNSPEC on frame F or nil if UNSPEC
2524 is not an unspecified foreground or background color. */
2526 static Lisp_Object
2527 frame_unspecified_color (struct frame *f, Lisp_Object unspec)
2529 return (!strncmp (SSDATA (unspec), unspecified_bg, SBYTES (unspec))
2530 ? tty_color_name (f, FRAME_BACKGROUND_PIXEL (f))
2531 : (!strncmp (SSDATA (unspec), unspecified_fg, SBYTES (unspec))
2532 ? tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)) : Qnil));
2535 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2536 doc: /* Return the parameters-alist of frame FRAME.
2537 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2538 The meaningful PARMs depend on the kind of frame.
2539 If FRAME is omitted or nil, return information on the currently selected frame. */)
2540 (Lisp_Object frame)
2542 Lisp_Object alist;
2543 struct frame *f = decode_any_frame (frame);
2544 int height, width;
2546 if (!FRAME_LIVE_P (f))
2547 return Qnil;
2549 alist = Fcopy_alist (f->param_alist);
2551 if (!FRAME_WINDOW_P (f))
2553 Lisp_Object elt;
2555 /* If the frame's parameter alist says the colors are
2556 unspecified and reversed, take the frame's background pixel
2557 for foreground and vice versa. */
2558 elt = Fassq (Qforeground_color, alist);
2559 if (CONSP (elt) && STRINGP (XCDR (elt)))
2561 elt = frame_unspecified_color (f, XCDR (elt));
2562 if (!NILP (elt))
2563 store_in_alist (&alist, Qforeground_color, elt);
2565 else
2566 store_in_alist (&alist, Qforeground_color,
2567 tty_color_name (f, FRAME_FOREGROUND_PIXEL (f)));
2568 elt = Fassq (Qbackground_color, alist);
2569 if (CONSP (elt) && STRINGP (XCDR (elt)))
2571 elt = frame_unspecified_color (f, XCDR (elt));
2572 if (!NILP (elt))
2573 store_in_alist (&alist, Qbackground_color, elt);
2575 else
2576 store_in_alist (&alist, Qbackground_color,
2577 tty_color_name (f, FRAME_BACKGROUND_PIXEL (f)));
2578 store_in_alist (&alist, Qfont,
2579 build_string (FRAME_MSDOS_P (f)
2580 ? "ms-dos"
2581 : FRAME_W32_P (f) ? "w32term"
2582 :"tty"));
2584 store_in_alist (&alist, Qname, f->name);
2585 height = (f->new_height
2586 ? (f->new_pixelwise
2587 ? (f->new_height / FRAME_LINE_HEIGHT (f))
2588 : f->new_height)
2589 : FRAME_LINES (f));
2590 store_in_alist (&alist, Qheight, make_number (height));
2591 width = (f->new_width
2592 ? (f->new_pixelwise
2593 ? (f->new_width / FRAME_COLUMN_WIDTH (f))
2594 : f->new_width)
2595 : FRAME_COLS (f));
2596 store_in_alist (&alist, Qwidth, make_number (width));
2597 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2598 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2599 store_in_alist (&alist, Qbuffer_list, f->buffer_list);
2600 store_in_alist (&alist, Qburied_buffer_list, f->buried_buffer_list);
2602 /* I think this should be done with a hook. */
2603 #ifdef HAVE_WINDOW_SYSTEM
2604 if (FRAME_WINDOW_P (f))
2605 x_report_frame_params (f, &alist);
2606 else
2607 #endif
2609 /* This ought to be correct in f->param_alist for an X frame. */
2610 Lisp_Object lines;
2611 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2612 store_in_alist (&alist, Qmenu_bar_lines, lines);
2615 return alist;
2619 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2620 doc: /* Return FRAME's value for parameter PARAMETER.
2621 If FRAME is nil, describe the currently selected frame. */)
2622 (Lisp_Object frame, Lisp_Object parameter)
2624 struct frame *f = decode_any_frame (frame);
2625 Lisp_Object value = Qnil;
2627 CHECK_SYMBOL (parameter);
2629 XSETFRAME (frame, f);
2631 if (FRAME_LIVE_P (f))
2633 /* Avoid consing in frequent cases. */
2634 if (EQ (parameter, Qname))
2635 value = f->name;
2636 #ifdef HAVE_WINDOW_SYSTEM
2637 /* These are used by vertical motion commands. */
2638 else if (EQ (parameter, Qvertical_scroll_bars))
2639 value = (f->vertical_scroll_bar_type == vertical_scroll_bar_none
2640 ? Qnil
2641 : (f->vertical_scroll_bar_type == vertical_scroll_bar_left
2642 ? Qleft : Qright));
2643 else if (EQ (parameter, Qhorizontal_scroll_bars))
2644 value = f->horizontal_scroll_bars ? Qt : Qnil;
2645 else if (EQ (parameter, Qline_spacing) && f->extra_line_spacing == 0)
2646 /* If this is non-zero, we can't determine whether the user specified
2647 an integer or float value without looking through 'param_alist'. */
2648 value = make_number (0);
2649 else if (EQ (parameter, Qfont) && FRAME_X_P (f))
2650 value = FRAME_FONT (f)->props[FONT_NAME_INDEX];
2651 #endif /* HAVE_WINDOW_SYSTEM */
2652 #ifdef HAVE_X_WINDOWS
2653 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2654 value = XCAR (FRAME_DISPLAY_INFO (f)->name_list_element);
2655 #endif /* HAVE_X_WINDOWS */
2656 else if (EQ (parameter, Qbackground_color)
2657 || EQ (parameter, Qforeground_color))
2659 value = Fassq (parameter, f->param_alist);
2660 if (CONSP (value))
2662 value = XCDR (value);
2663 /* Fframe_parameters puts the actual fg/bg color names,
2664 even if f->param_alist says otherwise. This is
2665 important when param_alist's notion of colors is
2666 "unspecified". We need to do the same here. */
2667 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2669 Lisp_Object tem = frame_unspecified_color (f, value);
2671 if (!NILP (tem))
2672 value = tem;
2675 else
2676 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2678 else if (EQ (parameter, Qdisplay_type)
2679 || EQ (parameter, Qbackground_mode))
2680 value = Fcdr (Fassq (parameter, f->param_alist));
2681 else
2682 /* FIXME: Avoid this code path at all (as well as code duplication)
2683 by sharing more code with Fframe_parameters. */
2684 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2687 return value;
2691 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2692 Smodify_frame_parameters, 2, 2, 0,
2693 doc: /* Modify FRAME according to new values of its parameters in ALIST.
2694 If FRAME is nil, it defaults to the selected frame.
2695 ALIST is an alist of parameters to change and their new values.
2696 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2697 Which PARMs are meaningful depends on the kind of frame.
2698 The meaningful parameters are acted upon, i.e. the frame is changed
2699 according to their new values, and are also stored in the frame's
2700 parameter list so that `frame-parameters' will return them.
2701 PARMs that are not meaningful are still stored in the frame's parameter
2702 list, but are otherwise ignored.
2704 The value of frame parameter FOO can also be accessed
2705 as a frame-local binding for the variable FOO, if you have
2706 enabled such bindings for that variable with `make-variable-frame-local'.
2707 Note that this functionality is obsolete as of Emacs 22.2, and its
2708 use is not recommended. Explicitly check for a frame-parameter instead. */)
2709 (Lisp_Object frame, Lisp_Object alist)
2711 struct frame *f = decode_live_frame (frame);
2712 register Lisp_Object prop, val;
2714 CHECK_LIST (alist);
2716 /* I think this should be done with a hook. */
2717 #ifdef HAVE_WINDOW_SYSTEM
2718 if (FRAME_WINDOW_P (f))
2719 x_set_frame_parameters (f, alist);
2720 else
2721 #endif
2722 #ifdef MSDOS
2723 if (FRAME_MSDOS_P (f))
2724 IT_set_frame_parameters (f, alist);
2725 else
2726 #endif
2729 EMACS_INT length = XFASTINT (Flength (alist));
2730 ptrdiff_t i;
2731 Lisp_Object *parms;
2732 Lisp_Object *values;
2733 USE_SAFE_ALLOCA;
2734 SAFE_ALLOCA_LISP (parms, 2 * length);
2735 values = parms + length;
2737 /* Extract parm names and values into those vectors. */
2739 for (i = 0; CONSP (alist); alist = XCDR (alist))
2741 Lisp_Object elt;
2743 elt = XCAR (alist);
2744 parms[i] = Fcar (elt);
2745 values[i] = Fcdr (elt);
2746 i++;
2749 /* Now process them in reverse of specified order. */
2750 while (--i >= 0)
2752 prop = parms[i];
2753 val = values[i];
2754 store_frame_param (f, prop, val);
2756 if (EQ (prop, Qforeground_color)
2757 || EQ (prop, Qbackground_color))
2758 update_face_from_frame_parameter (f, prop, val);
2761 SAFE_FREE ();
2763 return Qnil;
2766 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2767 0, 1, 0,
2768 doc: /* Height in pixels of a line in the font in frame FRAME.
2769 If FRAME is omitted or nil, the selected frame is used.
2770 For a terminal frame, the value is always 1. */)
2771 (Lisp_Object frame)
2773 #ifdef HAVE_WINDOW_SYSTEM
2774 struct frame *f = decode_any_frame (frame);
2776 if (FRAME_WINDOW_P (f))
2777 return make_number (FRAME_LINE_HEIGHT (f));
2778 else
2779 #endif
2780 return make_number (1);
2784 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2785 0, 1, 0,
2786 doc: /* Width in pixels of characters in the font in frame FRAME.
2787 If FRAME is omitted or nil, the selected frame is used.
2788 On a graphical screen, the width is the standard width of the default font.
2789 For a terminal screen, the value is always 1. */)
2790 (Lisp_Object frame)
2792 #ifdef HAVE_WINDOW_SYSTEM
2793 struct frame *f = decode_any_frame (frame);
2795 if (FRAME_WINDOW_P (f))
2796 return make_number (FRAME_COLUMN_WIDTH (f));
2797 else
2798 #endif
2799 return make_number (1);
2802 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2803 Sframe_pixel_height, 0, 1, 0,
2804 doc: /* Return a FRAME's height in pixels.
2805 If FRAME is omitted or nil, the selected frame is used. The exact value
2806 of the result depends on the window-system and toolkit in use:
2808 In the Gtk+ version of Emacs, it includes only any window (including
2809 the minibuffer or echo area), mode line, and header line. It does not
2810 include the tool bar or menu bar.
2812 With other graphical versions, it also includes the tool bar and the
2813 menu bar.
2815 For a text terminal, it includes the menu bar. In this case, the
2816 result is really in characters rather than pixels (i.e., is identical
2817 to `frame-height'). */)
2818 (Lisp_Object frame)
2820 struct frame *f = decode_any_frame (frame);
2822 #ifdef HAVE_WINDOW_SYSTEM
2823 if (FRAME_WINDOW_P (f))
2824 return make_number (FRAME_PIXEL_HEIGHT (f));
2825 else
2826 #endif
2827 return make_number (FRAME_TOTAL_LINES (f));
2830 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2831 Sframe_pixel_width, 0, 1, 0,
2832 doc: /* Return FRAME's width in pixels.
2833 For a terminal frame, the result really gives the width in characters.
2834 If FRAME is omitted or nil, the selected frame is used. */)
2835 (Lisp_Object frame)
2837 struct frame *f = decode_any_frame (frame);
2839 #ifdef HAVE_WINDOW_SYSTEM
2840 if (FRAME_WINDOW_P (f))
2841 return make_number (FRAME_PIXEL_WIDTH (f));
2842 else
2843 #endif
2844 return make_number (FRAME_TOTAL_COLS (f));
2847 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2848 Stool_bar_pixel_width, 0, 1, 0,
2849 doc: /* Return width in pixels of FRAME's tool bar.
2850 The result is greater than zero only when the tool bar is on the left
2851 or right side of FRAME. If FRAME is omitted or nil, the selected frame
2852 is used. */)
2853 (Lisp_Object frame)
2855 #ifdef FRAME_TOOLBAR_WIDTH
2856 struct frame *f = decode_any_frame (frame);
2858 if (FRAME_WINDOW_P (f))
2859 return make_number (FRAME_TOOLBAR_WIDTH (f));
2860 #endif
2861 return make_number (0);
2864 DEFUN ("frame-text-cols", Fframe_text_cols, Sframe_text_cols, 0, 1, 0,
2865 doc: /* Return width in columns of FRAME's text area. */)
2866 (Lisp_Object frame)
2868 return make_number (FRAME_COLS (decode_any_frame (frame)));
2871 DEFUN ("frame-text-lines", Fframe_text_lines, Sframe_text_lines, 0, 1, 0,
2872 doc: /* Return height in lines of FRAME's text area. */)
2873 (Lisp_Object frame)
2875 return make_number (FRAME_LINES (decode_any_frame (frame)));
2878 DEFUN ("frame-total-cols", Fframe_total_cols, Sframe_total_cols, 0, 1, 0,
2879 doc: /* Return number of total columns of FRAME. */)
2880 (Lisp_Object frame)
2882 return make_number (FRAME_TOTAL_COLS (decode_any_frame (frame)));
2885 DEFUN ("frame-total-lines", Fframe_total_lines, Sframe_total_lines, 0, 1, 0,
2886 doc: /* Return number of total lines of FRAME. */)
2887 (Lisp_Object frame)
2889 return make_number (FRAME_TOTAL_LINES (decode_any_frame (frame)));
2892 DEFUN ("frame-text-width", Fframe_text_width, Sframe_text_width, 0, 1, 0,
2893 doc: /* Return text area width of FRAME in pixels. */)
2894 (Lisp_Object frame)
2896 return make_number (FRAME_TEXT_WIDTH (decode_any_frame (frame)));
2899 DEFUN ("frame-text-height", Fframe_text_height, Sframe_text_height, 0, 1, 0,
2900 doc: /* Return text area height of FRAME in pixels. */)
2901 (Lisp_Object frame)
2903 return make_number (FRAME_TEXT_HEIGHT (decode_any_frame (frame)));
2906 DEFUN ("frame-scroll-bar-width", Fscroll_bar_width, Sscroll_bar_width, 0, 1, 0,
2907 doc: /* Return scroll bar width of FRAME in pixels. */)
2908 (Lisp_Object frame)
2910 return make_number (FRAME_SCROLL_BAR_AREA_WIDTH (decode_any_frame (frame)));
2913 DEFUN ("frame-scroll-bar-height", Fscroll_bar_height, Sscroll_bar_height, 0, 1, 0,
2914 doc: /* Return scroll bar height of FRAME in pixels. */)
2915 (Lisp_Object frame)
2917 return make_number (FRAME_SCROLL_BAR_AREA_HEIGHT (decode_any_frame (frame)));
2920 DEFUN ("frame-fringe-width", Ffringe_width, Sfringe_width, 0, 1, 0,
2921 doc: /* Return fringe width of FRAME in pixels. */)
2922 (Lisp_Object frame)
2924 return make_number (FRAME_TOTAL_FRINGE_WIDTH (decode_any_frame (frame)));
2927 DEFUN ("frame-border-width", Fborder_width, Sborder_width, 0, 1, 0,
2928 doc: /* Return border width of FRAME in pixels. */)
2929 (Lisp_Object frame)
2931 return make_number (FRAME_INTERNAL_BORDER_WIDTH (decode_any_frame (frame)));
2934 DEFUN ("frame-right-divider-width", Fright_divider_width, Sright_divider_width, 0, 1, 0,
2935 doc: /* Return width (in pixels) of vertical window dividers on FRAME. */)
2936 (Lisp_Object frame)
2938 return make_number (FRAME_RIGHT_DIVIDER_WIDTH (decode_any_frame (frame)));
2941 DEFUN ("frame-bottom-divider-width", Fbottom_divider_width, Sbottom_divider_width, 0, 1, 0,
2942 doc: /* Return width (in pixels) of horizontal window dividers on FRAME. */)
2943 (Lisp_Object frame)
2945 return make_number (FRAME_BOTTOM_DIVIDER_WIDTH (decode_any_frame (frame)));
2948 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 4, 0,
2949 doc: /* Set text height of frame FRAME to HEIGHT lines.
2950 Optional third arg PRETEND non-nil means that redisplay should use
2951 HEIGHT lines but that the idea of the actual height of the frame should
2952 not be changed.
2954 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2955 HEIGHT pixels high. Note: When `frame-resize-pixelwise' is nil, some
2956 window managers may refuse to honor a HEIGHT that is not an integer
2957 multiple of the default frame font height. */)
2958 (Lisp_Object frame, Lisp_Object height, Lisp_Object pretend, Lisp_Object pixelwise)
2960 struct frame *f = decode_live_frame (frame);
2961 int pixel_height;
2963 CHECK_TYPE_RANGED_INTEGER (int, height);
2965 pixel_height = (!NILP (pixelwise)
2966 ? XINT (height)
2967 : XINT (height) * FRAME_LINE_HEIGHT (f));
2968 adjust_frame_size (f, -1, pixel_height, 1, !NILP (pretend), Qheight);
2970 return Qnil;
2973 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 4, 0,
2974 doc: /* Set text width of frame FRAME to WIDTH columns.
2975 Optional third arg PRETEND non-nil means that redisplay should use WIDTH
2976 columns but that the idea of the actual width of the frame should not
2977 be changed.
2979 Optional fourth argument PIXELWISE non-nil means that FRAME should be
2980 WIDTH pixels wide. Note: When `frame-resize-pixelwise' is nil, some
2981 window managers may refuse to honor a WIDTH that is not an integer
2982 multiple of the default frame font width. */)
2983 (Lisp_Object frame, Lisp_Object width, Lisp_Object pretend, Lisp_Object pixelwise)
2985 struct frame *f = decode_live_frame (frame);
2986 int pixel_width;
2988 CHECK_TYPE_RANGED_INTEGER (int, width);
2990 pixel_width = (!NILP (pixelwise)
2991 ? XINT (width)
2992 : XINT (width) * FRAME_COLUMN_WIDTH (f));
2993 adjust_frame_size (f, pixel_width, -1, 1, !NILP (pretend), Qwidth);
2995 return Qnil;
2998 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 4, 0,
2999 doc: /* Set text size of FRAME to WIDTH by HEIGHT, measured in characters.
3000 Optional argument PIXELWISE non-nil means to measure in pixels. Note:
3001 When `frame-resize-pixelwise' is nil, some window managers may refuse to
3002 honor a WIDTH that is not an integer multiple of the default frame font
3003 width or a HEIGHT that is not an integer multiple of the default frame
3004 font height. */)
3005 (Lisp_Object frame, Lisp_Object width, Lisp_Object height, Lisp_Object pixelwise)
3007 struct frame *f = decode_live_frame (frame);
3008 int pixel_width, pixel_height;
3010 CHECK_TYPE_RANGED_INTEGER (int, width);
3011 CHECK_TYPE_RANGED_INTEGER (int, height);
3013 pixel_width = (!NILP (pixelwise)
3014 ? XINT (width)
3015 : XINT (width) * FRAME_COLUMN_WIDTH (f));
3016 pixel_height = (!NILP (pixelwise)
3017 ? XINT (height)
3018 : XINT (height) * FRAME_LINE_HEIGHT (f));
3019 adjust_frame_size (f, pixel_width, pixel_height, 1, 0, Qsize);
3021 return Qnil;
3024 DEFUN ("frame-position", Fframe_position,
3025 Sframe_position, 0, 1, 0,
3026 doc: /* Return top left corner of FRAME in pixels.
3027 FRAME must be a live frame and defaults to the selected one. The return
3028 value is a cons (x, y) of the coordinates of the top left corner of
3029 FRAME's outer frame, in pixels relative to an origin (0, 0) of FRAME's
3030 display. */)
3031 (Lisp_Object frame)
3033 register struct frame *f = decode_live_frame (frame);
3035 return Fcons (make_number (f->left_pos), make_number (f->top_pos));
3038 DEFUN ("set-frame-position", Fset_frame_position,
3039 Sset_frame_position, 3, 3, 0,
3040 doc: /* Set position of FRAME to (X, Y).
3041 FRAME must be a live frame and defaults to the selected one. X and Y,
3042 if positive, specify the coordinate of the left and top edge of FRAME's
3043 outer frame in pixels relative to an origin (0, 0) of FRAME's display.
3044 If any of X or Y is negative, it specifies the coordinates of the right
3045 or bottom edge of the outer frame of FRAME relative to the right or
3046 bottom edge of FRAME's display. */)
3047 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
3049 struct frame *f = decode_live_frame (frame);
3051 CHECK_TYPE_RANGED_INTEGER (int, x);
3052 CHECK_TYPE_RANGED_INTEGER (int, y);
3054 /* I think this should be done with a hook. */
3055 if (FRAME_WINDOW_P (f))
3057 #ifdef HAVE_WINDOW_SYSTEM
3058 x_set_offset (f, XINT (x), XINT (y), 1);
3059 #endif
3062 return Qt;
3066 /***********************************************************************
3067 Frame Parameters
3068 ***********************************************************************/
3070 /* Connect the frame-parameter names for X frames
3071 to the ways of passing the parameter values to the window system.
3073 The name of a parameter, as a Lisp symbol,
3074 has an `x-frame-parameter' property which is an integer in Lisp
3075 that is an index in this table. */
3077 struct frame_parm_table {
3078 const char *name;
3079 int sym;
3082 static const struct frame_parm_table frame_parms[] =
3084 {"auto-raise", SYMBOL_INDEX (Qauto_raise)},
3085 {"auto-lower", SYMBOL_INDEX (Qauto_lower)},
3086 {"background-color", -1},
3087 {"border-color", SYMBOL_INDEX (Qborder_color)},
3088 {"border-width", SYMBOL_INDEX (Qborder_width)},
3089 {"cursor-color", SYMBOL_INDEX (Qcursor_color)},
3090 {"cursor-type", SYMBOL_INDEX (Qcursor_type)},
3091 {"font", -1},
3092 {"foreground-color", -1},
3093 {"icon-name", SYMBOL_INDEX (Qicon_name)},
3094 {"icon-type", SYMBOL_INDEX (Qicon_type)},
3095 {"internal-border-width", SYMBOL_INDEX (Qinternal_border_width)},
3096 {"right-divider-width", SYMBOL_INDEX (Qright_divider_width)},
3097 {"bottom-divider-width", SYMBOL_INDEX (Qbottom_divider_width)},
3098 {"menu-bar-lines", SYMBOL_INDEX (Qmenu_bar_lines)},
3099 {"mouse-color", SYMBOL_INDEX (Qmouse_color)},
3100 {"name", SYMBOL_INDEX (Qname)},
3101 {"scroll-bar-width", SYMBOL_INDEX (Qscroll_bar_width)},
3102 {"scroll-bar-height", SYMBOL_INDEX (Qscroll_bar_height)},
3103 {"title", SYMBOL_INDEX (Qtitle)},
3104 {"unsplittable", SYMBOL_INDEX (Qunsplittable)},
3105 {"vertical-scroll-bars", SYMBOL_INDEX (Qvertical_scroll_bars)},
3106 {"horizontal-scroll-bars", SYMBOL_INDEX (Qhorizontal_scroll_bars)},
3107 {"visibility", SYMBOL_INDEX (Qvisibility)},
3108 {"tool-bar-lines", SYMBOL_INDEX (Qtool_bar_lines)},
3109 {"scroll-bar-foreground", SYMBOL_INDEX (Qscroll_bar_foreground)},
3110 {"scroll-bar-background", SYMBOL_INDEX (Qscroll_bar_background)},
3111 {"screen-gamma", SYMBOL_INDEX (Qscreen_gamma)},
3112 {"line-spacing", SYMBOL_INDEX (Qline_spacing)},
3113 {"left-fringe", SYMBOL_INDEX (Qleft_fringe)},
3114 {"right-fringe", SYMBOL_INDEX (Qright_fringe)},
3115 {"wait-for-wm", SYMBOL_INDEX (Qwait_for_wm)},
3116 {"fullscreen", SYMBOL_INDEX (Qfullscreen)},
3117 {"font-backend", SYMBOL_INDEX (Qfont_backend)},
3118 {"alpha", SYMBOL_INDEX (Qalpha)},
3119 {"sticky", SYMBOL_INDEX (Qsticky)},
3120 {"tool-bar-position", SYMBOL_INDEX (Qtool_bar_position)},
3123 #ifdef HAVE_WINDOW_SYSTEM
3125 /* Change the parameters of frame F as specified by ALIST.
3126 If a parameter is not specially recognized, do nothing special;
3127 otherwise call the `x_set_...' function for that parameter.
3128 Except for certain geometry properties, always call store_frame_param
3129 to store the new value in the parameter alist. */
3131 void
3132 x_set_frame_parameters (struct frame *f, Lisp_Object alist)
3134 Lisp_Object tail;
3136 /* If both of these parameters are present, it's more efficient to
3137 set them both at once. So we wait until we've looked at the
3138 entire list before we set them. */
3139 int width, height;
3140 bool width_change = false, height_change = false;
3142 /* Same here. */
3143 Lisp_Object left, top;
3145 /* Same with these. */
3146 Lisp_Object icon_left, icon_top;
3148 /* And with this. */
3149 Lisp_Object fullscreen;
3150 bool fullscreen_change = false;
3152 /* Record in these vectors all the parms specified. */
3153 Lisp_Object *parms;
3154 Lisp_Object *values;
3155 ptrdiff_t i, j, size;
3156 bool left_no_change = 0, top_no_change = 0;
3157 #ifdef HAVE_X_WINDOWS
3158 bool icon_left_no_change = 0, icon_top_no_change = 0;
3159 #endif
3161 for (size = 0, tail = alist; CONSP (tail); tail = XCDR (tail))
3162 size++;
3164 USE_SAFE_ALLOCA;
3165 SAFE_ALLOCA_LISP (parms, 2 * size);
3166 values = parms + size;
3168 /* Extract parm names and values into those vectors. */
3170 i = 0, j = size - 1;
3171 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3173 Lisp_Object elt = XCAR (tail), prop = Fcar (elt), val = Fcdr (elt);
3175 /* Some properties are independent of other properties, but other
3176 properties are dependent upon them. These special properties
3177 are foreground_color, background_color (affects cursor_color)
3178 and font (affects fringe widths); they're recorded starting
3179 from the end of PARMS and VALUES to process them first by using
3180 reverse iteration. */
3182 if (EQ (prop, Qforeground_color)
3183 || EQ (prop, Qbackground_color)
3184 || EQ (prop, Qfont))
3186 parms[j] = prop;
3187 values[j] = val;
3188 j--;
3190 else
3192 parms[i] = prop;
3193 values[i] = val;
3194 i++;
3198 /* TAIL and ALIST are not used again below here. */
3199 alist = tail = Qnil;
3201 top = left = Qunbound;
3202 icon_left = icon_top = Qunbound;
3204 /* Reverse order is used to make sure that special
3205 properties noticed above are processed first. */
3206 for (i = size - 1; i >= 0; i--)
3208 Lisp_Object prop, val;
3210 prop = parms[i];
3211 val = values[i];
3213 if (EQ (prop, Qwidth))
3215 if (RANGED_INTEGERP (0, val, INT_MAX))
3217 width = XFASTINT (val) * FRAME_COLUMN_WIDTH (f) ;
3218 width_change = true;
3220 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3221 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3223 width = XFASTINT (XCDR (val));
3224 width_change = true;
3227 else if (EQ (prop, Qheight))
3229 if (RANGED_INTEGERP (0, val, INT_MAX))
3231 height = XFASTINT (val) * FRAME_LINE_HEIGHT (f);
3232 height_change = true;
3234 else if (CONSP (val) && EQ (XCAR (val), Qtext_pixels)
3235 && RANGED_INTEGERP (0, XCDR (val), INT_MAX))
3237 height = XFASTINT (XCDR (val));
3238 height_change = true;
3241 else if (EQ (prop, Qtop))
3242 top = val;
3243 else if (EQ (prop, Qleft))
3244 left = val;
3245 else if (EQ (prop, Qicon_top))
3246 icon_top = val;
3247 else if (EQ (prop, Qicon_left))
3248 icon_left = val;
3249 else if (EQ (prop, Qfullscreen))
3251 fullscreen = val;
3252 fullscreen_change = true;
3254 else
3256 register Lisp_Object param_index, old_value;
3258 old_value = get_frame_param (f, prop);
3260 store_frame_param (f, prop, val);
3262 param_index = Fget (prop, Qx_frame_parameter);
3263 if (NATNUMP (param_index)
3264 && XFASTINT (param_index) < ARRAYELTS (frame_parms)
3265 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3266 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3270 /* Don't die if just one of these was set. */
3271 if (EQ (left, Qunbound))
3273 left_no_change = 1;
3274 if (f->left_pos < 0)
3275 left = list2 (Qplus, make_number (f->left_pos));
3276 else
3277 XSETINT (left, f->left_pos);
3279 if (EQ (top, Qunbound))
3281 top_no_change = 1;
3282 if (f->top_pos < 0)
3283 top = list2 (Qplus, make_number (f->top_pos));
3284 else
3285 XSETINT (top, f->top_pos);
3288 /* If one of the icon positions was not set, preserve or default it. */
3289 if (! TYPE_RANGED_INTEGERP (int, icon_left))
3291 #ifdef HAVE_X_WINDOWS
3292 icon_left_no_change = 1;
3293 #endif
3294 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3295 if (NILP (icon_left))
3296 XSETINT (icon_left, 0);
3298 if (! TYPE_RANGED_INTEGERP (int, icon_top))
3300 #ifdef HAVE_X_WINDOWS
3301 icon_top_no_change = 1;
3302 #endif
3303 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3304 if (NILP (icon_top))
3305 XSETINT (icon_top, 0);
3308 /* Don't set these parameters unless they've been explicitly
3309 specified. The window might be mapped or resized while we're in
3310 this function, and we don't want to override that unless the lisp
3311 code has asked for it.
3313 Don't set these parameters unless they actually differ from the
3314 window's current parameters; the window may not actually exist
3315 yet. */
3317 Lisp_Object frame;
3319 XSETFRAME (frame, f);
3321 if ((width_change && width != FRAME_TEXT_WIDTH (f))
3322 || (height_change && height != FRAME_TEXT_HEIGHT (f)))
3323 /* We could consider checking f->after_make_frame here, but I
3324 don't have the faintest idea why the following is needed at
3325 all. With the old setting it can get a Heisenbug when
3326 EmacsFrameResize intermittently provokes a delayed
3327 change_frame_size in the middle of adjust_frame_size. */
3328 /** || (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
3329 adjust_frame_size (f, width_change ? width : -1,
3330 height_change ? height : -1, 1, 0, Qx_set_frame_parameters);
3332 if ((!NILP (left) || !NILP (top))
3333 && ! (left_no_change && top_no_change)
3334 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3335 && NUMBERP (top) && XINT (top) == f->top_pos))
3337 int leftpos = 0;
3338 int toppos = 0;
3340 /* Record the signs. */
3341 f->size_hint_flags &= ~ (XNegative | YNegative);
3342 if (EQ (left, Qminus))
3343 f->size_hint_flags |= XNegative;
3344 else if (TYPE_RANGED_INTEGERP (int, left))
3346 leftpos = XINT (left);
3347 if (leftpos < 0)
3348 f->size_hint_flags |= XNegative;
3350 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3351 && CONSP (XCDR (left))
3352 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3354 leftpos = - XINT (XCAR (XCDR (left)));
3355 f->size_hint_flags |= XNegative;
3357 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3358 && CONSP (XCDR (left))
3359 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3361 leftpos = XINT (XCAR (XCDR (left)));
3364 if (EQ (top, Qminus))
3365 f->size_hint_flags |= YNegative;
3366 else if (TYPE_RANGED_INTEGERP (int, top))
3368 toppos = XINT (top);
3369 if (toppos < 0)
3370 f->size_hint_flags |= YNegative;
3372 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3373 && CONSP (XCDR (top))
3374 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3376 toppos = - XINT (XCAR (XCDR (top)));
3377 f->size_hint_flags |= YNegative;
3379 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3380 && CONSP (XCDR (top))
3381 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3383 toppos = XINT (XCAR (XCDR (top)));
3387 /* Store the numeric value of the position. */
3388 f->top_pos = toppos;
3389 f->left_pos = leftpos;
3391 f->win_gravity = NorthWestGravity;
3393 /* Actually set that position, and convert to absolute. */
3394 x_set_offset (f, leftpos, toppos, -1);
3397 if (fullscreen_change)
3399 Lisp_Object old_value = get_frame_param (f, Qfullscreen);
3401 frame_size_history_add
3402 (f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
3404 store_frame_param (f, Qfullscreen, fullscreen);
3405 if (!EQ (fullscreen, old_value))
3406 x_set_fullscreen (f, fullscreen, old_value);
3410 #ifdef HAVE_X_WINDOWS
3411 if ((!NILP (icon_left) || !NILP (icon_top))
3412 && ! (icon_left_no_change && icon_top_no_change))
3413 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3414 #endif /* HAVE_X_WINDOWS */
3417 SAFE_FREE ();
3421 /* Insert a description of internally-recorded parameters of frame X
3422 into the parameter alist *ALISTPTR that is to be given to the user.
3423 Only parameters that are specific to the X window system
3424 and whose values are not correctly recorded in the frame's
3425 param_alist need to be considered here. */
3427 void
3428 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3430 Lisp_Object tem;
3431 uprintmax_t w;
3432 char buf[INT_BUFSIZE_BOUND (w)];
3434 /* Represent negative positions (off the top or left screen edge)
3435 in a way that Fmodify_frame_parameters will understand correctly. */
3436 XSETINT (tem, f->left_pos);
3437 if (f->left_pos >= 0)
3438 store_in_alist (alistptr, Qleft, tem);
3439 else
3440 store_in_alist (alistptr, Qleft, list2 (Qplus, tem));
3442 XSETINT (tem, f->top_pos);
3443 if (f->top_pos >= 0)
3444 store_in_alist (alistptr, Qtop, tem);
3445 else
3446 store_in_alist (alistptr, Qtop, list2 (Qplus, tem));
3448 store_in_alist (alistptr, Qborder_width,
3449 make_number (f->border_width));
3450 store_in_alist (alistptr, Qinternal_border_width,
3451 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3452 store_in_alist (alistptr, Qright_divider_width,
3453 make_number (FRAME_RIGHT_DIVIDER_WIDTH (f)));
3454 store_in_alist (alistptr, Qbottom_divider_width,
3455 make_number (FRAME_BOTTOM_DIVIDER_WIDTH (f)));
3456 store_in_alist (alistptr, Qleft_fringe,
3457 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3458 store_in_alist (alistptr, Qright_fringe,
3459 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3460 store_in_alist (alistptr, Qscroll_bar_width,
3461 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3462 ? make_number (0)
3463 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3464 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3465 /* nil means "use default width"
3466 for non-toolkit scroll bar.
3467 ruler-mode.el depends on this. */
3468 : Qnil));
3469 store_in_alist (alistptr, Qscroll_bar_height,
3470 (! FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)
3471 ? make_number (0)
3472 : FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) > 0
3473 ? make_number (FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3474 /* nil means "use default height"
3475 for non-toolkit scroll bar. */
3476 : Qnil));
3477 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3478 MS-Windows it returns a value whose type is HANDLE, which is
3479 actually a pointer. Explicit casting avoids compiler
3480 warnings. */
3481 w = (uintptr_t) FRAME_X_WINDOW (f);
3482 store_in_alist (alistptr, Qwindow_id,
3483 make_formatted_string (buf, "%"pMu, w));
3484 #ifdef HAVE_X_WINDOWS
3485 #ifdef USE_X_TOOLKIT
3486 /* Tooltip frame may not have this widget. */
3487 if (FRAME_X_OUTPUT (f)->widget)
3488 #endif
3489 w = (uintptr_t) FRAME_OUTER_WINDOW (f);
3490 store_in_alist (alistptr, Qouter_window_id,
3491 make_formatted_string (buf, "%"pMu, w));
3492 #endif
3493 store_in_alist (alistptr, Qicon_name, f->icon_name);
3494 store_in_alist (alistptr, Qvisibility,
3495 (FRAME_VISIBLE_P (f) ? Qt
3496 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3497 store_in_alist (alistptr, Qdisplay,
3498 XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
3500 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
3501 tem = Qnil;
3502 else
3503 tem = make_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
3504 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3505 store_in_alist (alistptr, Qparent_id, tem);
3506 store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
3510 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3511 the previous value of that parameter, NEW_VALUE is the new value. */
3513 void
3514 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3516 if (NILP (new_value))
3517 f->want_fullscreen = FULLSCREEN_NONE;
3518 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3519 f->want_fullscreen = FULLSCREEN_BOTH;
3520 else if (EQ (new_value, Qfullwidth))
3521 f->want_fullscreen = FULLSCREEN_WIDTH;
3522 else if (EQ (new_value, Qfullheight))
3523 f->want_fullscreen = FULLSCREEN_HEIGHT;
3524 else if (EQ (new_value, Qmaximized))
3525 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3527 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3528 FRAME_TERMINAL (f)->fullscreen_hook (f);
3532 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3533 the previous value of that parameter, NEW_VALUE is the new value. */
3535 void
3536 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3538 if (NILP (new_value))
3539 f->extra_line_spacing = 0;
3540 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3541 f->extra_line_spacing = XFASTINT (new_value);
3542 else if (FLOATP (new_value))
3544 int new_spacing = XFLOAT_DATA (new_value) * FRAME_LINE_HEIGHT (f) + 0.5;
3546 if (new_spacing >= 0)
3547 f->extra_line_spacing = new_spacing;
3548 else
3549 signal_error ("Invalid line-spacing", new_value);
3551 else
3552 signal_error ("Invalid line-spacing", new_value);
3553 if (FRAME_VISIBLE_P (f))
3554 redraw_frame (f);
3558 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3559 the previous value of that parameter, NEW_VALUE is the new value. */
3561 void
3562 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3564 Lisp_Object bgcolor;
3566 if (NILP (new_value))
3567 f->gamma = 0;
3568 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3569 /* The value 0.4545 is the normal viewing gamma. */
3570 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3571 else
3572 signal_error ("Invalid screen-gamma", new_value);
3574 /* Apply the new gamma value to the frame background. */
3575 bgcolor = Fassq (Qbackground_color, f->param_alist);
3576 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3578 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3579 if (NATNUMP (parm_index)
3580 && XFASTINT (parm_index) < ARRAYELTS (frame_parms)
3581 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3582 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3583 (f, bgcolor, Qnil);
3586 clear_face_cache (true); /* FIXME: Why of all frames? */
3587 fset_redisplay (f);
3591 void
3592 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3594 Lisp_Object font_object;
3595 int fontset = -1;
3596 #ifdef HAVE_X_WINDOWS
3597 Lisp_Object font_param = arg;
3598 #endif
3600 /* Set the frame parameter back to the old value because we may
3601 fail to use ARG as the new parameter value. */
3602 store_frame_param (f, Qfont, oldval);
3604 /* ARG is a fontset name, a font name, a cons of fontset name and a
3605 font object, or a font object. In the last case, this function
3606 never fail. */
3607 if (STRINGP (arg))
3609 fontset = fs_query_fontset (arg, 0);
3610 if (fontset < 0)
3612 font_object = font_open_by_name (f, arg);
3613 if (NILP (font_object))
3614 error ("Font `%s' is not defined", SSDATA (arg));
3615 arg = AREF (font_object, FONT_NAME_INDEX);
3617 else if (fontset > 0)
3619 font_object = font_open_by_name (f, fontset_ascii (fontset));
3620 if (NILP (font_object))
3621 error ("Font `%s' is not defined", SDATA (arg));
3622 arg = AREF (font_object, FONT_NAME_INDEX);
3624 else
3625 error ("The default fontset can't be used for a frame font");
3627 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3629 /* This is the case that the ASCII font of F's fontset XCAR
3630 (arg) is changed to the font XCDR (arg) by
3631 `set-fontset-font'. */
3632 fontset = fs_query_fontset (XCAR (arg), 0);
3633 if (fontset < 0)
3634 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3635 font_object = XCDR (arg);
3636 arg = AREF (font_object, FONT_NAME_INDEX);
3637 #ifdef HAVE_X_WINDOWS
3638 font_param = Ffont_get (font_object, QCname);
3639 #endif
3641 else if (FONT_OBJECT_P (arg))
3643 font_object = arg;
3644 #ifdef HAVE_X_WINDOWS
3645 font_param = Ffont_get (font_object, QCname);
3646 #endif
3647 /* This is to store the XLFD font name in the frame parameter for
3648 backward compatibility. We should store the font-object
3649 itself in the future. */
3650 arg = AREF (font_object, FONT_NAME_INDEX);
3651 fontset = FRAME_FONTSET (f);
3652 /* Check if we can use the current fontset. If not, set FONTSET
3653 to -1 to generate a new fontset from FONT-OBJECT. */
3654 if (fontset >= 0)
3656 Lisp_Object ascii_font = fontset_ascii (fontset);
3657 Lisp_Object spec = font_spec_from_name (ascii_font);
3659 /* SPEC might be nil because ASCII_FONT's name doesn't parse
3660 according to stupid XLFD rules, which, for example,
3661 disallow font names that include a dash followed by a
3662 number. So in those cases we simply request x_new_font
3663 below to generate a new fontset. */
3664 if (NILP (spec) || ! font_match_p (spec, font_object))
3665 fontset = -1;
3668 else
3669 signal_error ("Invalid font", arg);
3671 if (! NILP (Fequal (font_object, oldval)))
3672 return;
3674 x_new_font (f, font_object, fontset);
3675 store_frame_param (f, Qfont, arg);
3676 #ifdef HAVE_X_WINDOWS
3677 store_frame_param (f, Qfont_parameter, font_param);
3678 #endif
3679 /* Recalculate toolbar height. */
3680 f->n_tool_bar_rows = 0;
3682 /* Ensure we redraw it. */
3683 clear_current_matrices (f);
3685 /* Attempt to hunt down bug#16028. */
3686 SET_FRAME_GARBAGED (f);
3688 /* This is important if we are called by some Lisp as part of
3689 redisplaying the frame, see redisplay_internal. */
3690 f->fonts_changed = true;
3692 recompute_basic_faces (f);
3694 do_pending_window_change (0);
3696 /* We used to call face-set-after-frame-default here, but it leads to
3697 recursive calls (since that function can set the `default' face's
3698 font which in turns changes the frame's `font' parameter).
3699 Also I don't know what this call is meant to do, but it seems the
3700 wrong way to do it anyway (it does a lot more work than what seems
3701 reasonable in response to a change to `font'). */
3705 void
3706 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3708 if (! NILP (new_value)
3709 && !CONSP (new_value))
3711 char *p0, *p1;
3713 CHECK_STRING (new_value);
3714 p0 = p1 = SSDATA (new_value);
3715 new_value = Qnil;
3716 while (*p0)
3718 while (*p1 && ! c_isspace (*p1) && *p1 != ',') p1++;
3719 if (p0 < p1)
3720 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3721 new_value);
3722 if (*p1)
3724 int c;
3726 while ((c = *++p1) && c_isspace (c));
3728 p0 = p1;
3730 new_value = Fnreverse (new_value);
3733 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3734 return;
3736 if (FRAME_FONT (f))
3737 free_all_realized_faces (Qnil);
3739 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3740 if (NILP (new_value))
3742 if (NILP (old_value))
3743 error ("No font backend available");
3744 font_update_drivers (f, old_value);
3745 error ("None of specified font backends are available");
3747 store_frame_param (f, Qfont_backend, new_value);
3749 if (FRAME_FONT (f))
3751 Lisp_Object frame;
3753 XSETFRAME (frame, f);
3754 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3755 face_change = true;
3756 windows_or_buffers_changed = 18;
3760 void
3761 x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3763 int unit = FRAME_COLUMN_WIDTH (f);
3764 int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
3765 int new_width;
3767 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3768 ? eabs (XINT (new_value)) : 8);
3770 if (new_width != old_width)
3772 f->left_fringe_width = new_width;
3773 f->fringe_cols /* Round up. */
3774 = (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
3776 if (FRAME_X_WINDOW (f) != 0)
3777 adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
3779 SET_FRAME_GARBAGED (f);
3784 void
3785 x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3787 int unit = FRAME_COLUMN_WIDTH (f);
3788 int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
3789 int new_width;
3791 new_width = (RANGED_INTEGERP (-INT_MAX, new_value, INT_MAX)
3792 ? eabs (XINT (new_value)) : 8);
3794 if (new_width != old_width)
3796 f->right_fringe_width = new_width;
3797 f->fringe_cols /* Round up. */
3798 = (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
3800 if (FRAME_X_WINDOW (f) != 0)
3801 adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
3803 SET_FRAME_GARBAGED (f);
3808 void
3809 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3811 CHECK_TYPE_RANGED_INTEGER (int, arg);
3813 if (XINT (arg) == f->border_width)
3814 return;
3816 if (FRAME_X_WINDOW (f) != 0)
3817 error ("Cannot change the border width of a frame");
3819 f->border_width = XINT (arg);
3822 void
3823 x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3825 int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
3826 CHECK_TYPE_RANGED_INTEGER (int, arg);
3827 int new = max (0, XINT (arg));
3828 if (new != old)
3830 f->right_divider_width = new;
3831 adjust_frame_size (f, -1, -1, 4, 0, Qright_divider_width);
3832 adjust_frame_glyphs (f);
3833 SET_FRAME_GARBAGED (f);
3838 void
3839 x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3841 int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
3842 CHECK_TYPE_RANGED_INTEGER (int, arg);
3843 int new = max (0, XINT (arg));
3844 if (new != old)
3846 f->bottom_divider_width = new;
3847 adjust_frame_size (f, -1, -1, 4, 0, Qbottom_divider_width);
3848 adjust_frame_glyphs (f);
3849 SET_FRAME_GARBAGED (f);
3853 void
3854 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3856 Lisp_Object frame;
3857 XSETFRAME (frame, f);
3859 if (NILP (value))
3860 Fmake_frame_invisible (frame, Qt);
3861 else if (EQ (value, Qicon))
3862 Ficonify_frame (frame);
3863 else
3864 Fmake_frame_visible (frame);
3867 void
3868 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3870 f->auto_raise = !EQ (Qnil, arg);
3873 void
3874 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3876 f->auto_lower = !EQ (Qnil, arg);
3879 void
3880 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3882 f->no_split = !NILP (arg);
3885 void
3886 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3888 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3889 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3890 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3891 || (!NILP (arg) && !FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3893 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3894 = (NILP (arg)
3895 ? vertical_scroll_bar_none
3896 : EQ (Qleft, arg)
3897 ? vertical_scroll_bar_left
3898 : EQ (Qright, arg)
3899 ? vertical_scroll_bar_right
3900 : EQ (Qleft, Vdefault_frame_scroll_bars)
3901 ? vertical_scroll_bar_left
3902 : EQ (Qright, Vdefault_frame_scroll_bars)
3903 ? vertical_scroll_bar_right
3904 : vertical_scroll_bar_none);
3906 /* We set this parameter before creating the X window for the
3907 frame, so we can get the geometry right from the start.
3908 However, if the window hasn't been created yet, we shouldn't
3909 call x_set_window_size. */
3910 if (FRAME_X_WINDOW (f))
3911 adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
3913 SET_FRAME_GARBAGED (f);
3917 void
3918 x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3920 #if USE_HORIZONTAL_SCROLL_BARS
3921 if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
3922 || (!NILP (arg) && !FRAME_HAS_HORIZONTAL_SCROLL_BARS (f)))
3924 f->horizontal_scroll_bars = NILP (arg) ? false : true;
3926 /* We set this parameter before creating the X window for the
3927 frame, so we can get the geometry right from the start.
3928 However, if the window hasn't been created yet, we shouldn't
3929 call x_set_window_size. */
3930 if (FRAME_X_WINDOW (f))
3931 adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
3933 SET_FRAME_GARBAGED (f);
3935 #endif
3938 void
3939 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3941 int unit = FRAME_COLUMN_WIDTH (f);
3943 if (NILP (arg))
3945 x_set_scroll_bar_default_width (f);
3947 if (FRAME_X_WINDOW (f))
3948 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3950 SET_FRAME_GARBAGED (f);
3952 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3953 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3955 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3956 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + unit - 1) / unit;
3957 if (FRAME_X_WINDOW (f))
3958 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
3960 SET_FRAME_GARBAGED (f);
3963 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3964 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3967 void
3968 x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3970 #if USE_HORIZONTAL_SCROLL_BARS
3971 int unit = FRAME_LINE_HEIGHT (f);
3973 if (NILP (arg))
3975 x_set_scroll_bar_default_height (f);
3977 if (FRAME_X_WINDOW (f))
3978 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3980 SET_FRAME_GARBAGED (f);
3982 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3983 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_HEIGHT (f))
3985 FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFASTINT (arg);
3986 FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFASTINT (arg) + unit - 1) / unit;
3987 if (FRAME_X_WINDOW (f))
3988 adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
3990 SET_FRAME_GARBAGED (f);
3993 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.vpos = 0;
3994 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.y = 0;
3995 #endif
3998 void
3999 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
4001 double alpha = 1.0;
4002 double newval[2];
4003 int i;
4004 Lisp_Object item;
4006 for (i = 0; i < 2; i++)
4008 newval[i] = 1.0;
4009 if (CONSP (arg))
4011 item = CAR (arg);
4012 arg = CDR (arg);
4014 else
4015 item = arg;
4017 if (NILP (item))
4018 alpha = - 1.0;
4019 else if (FLOATP (item))
4021 alpha = XFLOAT_DATA (item);
4022 if (! (0 <= alpha && alpha <= 1.0))
4023 args_out_of_range (make_float (0.0), make_float (1.0));
4025 else if (INTEGERP (item))
4027 EMACS_INT ialpha = XINT (item);
4028 if (! (0 <= ialpha && alpha <= 100))
4029 args_out_of_range (make_number (0), make_number (100));
4030 alpha = ialpha / 100.0;
4032 else
4033 wrong_type_argument (Qnumberp, item);
4034 newval[i] = alpha;
4037 for (i = 0; i < 2; i++)
4038 f->alpha[i] = newval[i];
4040 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
4041 block_input ();
4042 x_set_frame_alpha (f);
4043 unblock_input ();
4044 #endif
4046 return;
4049 #ifndef HAVE_NS
4051 /* Non-zero if mouse is grabbed on DPYINFO
4052 and we know the frame where it is. */
4054 bool x_mouse_grabbed (Display_Info *dpyinfo)
4056 return (dpyinfo->grabbed
4057 && dpyinfo->last_mouse_frame
4058 && FRAME_LIVE_P (dpyinfo->last_mouse_frame));
4061 /* Re-highlight something with mouse-face properties
4062 on DPYINFO using saved frame and mouse position. */
4064 void
4065 x_redo_mouse_highlight (Display_Info *dpyinfo)
4067 if (dpyinfo->last_mouse_motion_frame
4068 && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
4069 note_mouse_highlight (dpyinfo->last_mouse_motion_frame,
4070 dpyinfo->last_mouse_motion_x,
4071 dpyinfo->last_mouse_motion_y);
4074 #endif /* HAVE_NS */
4076 /* Subroutines of creating an X frame. */
4078 /* Make sure that Vx_resource_name is set to a reasonable value.
4079 Fix it up, or set it to `emacs' if it is too hopeless. */
4081 void
4082 validate_x_resource_name (void)
4084 ptrdiff_t len = 0;
4085 /* Number of valid characters in the resource name. */
4086 ptrdiff_t good_count = 0;
4087 /* Number of invalid characters in the resource name. */
4088 ptrdiff_t bad_count = 0;
4089 Lisp_Object new;
4090 ptrdiff_t i;
4092 if (!STRINGP (Vx_resource_class))
4093 Vx_resource_class = build_string (EMACS_CLASS);
4095 if (STRINGP (Vx_resource_name))
4097 unsigned char *p = SDATA (Vx_resource_name);
4099 len = SBYTES (Vx_resource_name);
4101 /* Only letters, digits, - and _ are valid in resource names.
4102 Count the valid characters and count the invalid ones. */
4103 for (i = 0; i < len; i++)
4105 int c = p[i];
4106 if (! ((c >= 'a' && c <= 'z')
4107 || (c >= 'A' && c <= 'Z')
4108 || (c >= '0' && c <= '9')
4109 || c == '-' || c == '_'))
4110 bad_count++;
4111 else
4112 good_count++;
4115 else
4116 /* Not a string => completely invalid. */
4117 bad_count = 5, good_count = 0;
4119 /* If name is valid already, return. */
4120 if (bad_count == 0)
4121 return;
4123 /* If name is entirely invalid, or nearly so, or is so implausibly
4124 large that alloca might not work, use `emacs'. */
4125 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
4127 Vx_resource_name = build_string ("emacs");
4128 return;
4131 /* Name is partly valid. Copy it and replace the invalid characters
4132 with underscores. */
4134 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
4136 for (i = 0; i < len; i++)
4138 int c = SREF (new, i);
4139 if (! ((c >= 'a' && c <= 'z')
4140 || (c >= 'A' && c <= 'Z')
4141 || (c >= '0' && c <= '9')
4142 || c == '-' || c == '_'))
4143 SSET (new, i, '_');
4147 /* Get specified attribute from resource database RDB.
4148 See Fx_get_resource below for other parameters. */
4150 static Lisp_Object
4151 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
4153 CHECK_STRING (attribute);
4154 CHECK_STRING (class);
4156 if (!NILP (component))
4157 CHECK_STRING (component);
4158 if (!NILP (subclass))
4159 CHECK_STRING (subclass);
4160 if (NILP (component) != NILP (subclass))
4161 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
4163 validate_x_resource_name ();
4165 /* Allocate space for the components, the dots which separate them,
4166 and the final '\0'. Make them big enough for the worst case. */
4167 ptrdiff_t name_keysize = (SBYTES (Vx_resource_name)
4168 + (STRINGP (component)
4169 ? SBYTES (component) : 0)
4170 + SBYTES (attribute)
4171 + 3);
4173 ptrdiff_t class_keysize = (SBYTES (Vx_resource_class)
4174 + SBYTES (class)
4175 + (STRINGP (subclass)
4176 ? SBYTES (subclass) : 0)
4177 + 3);
4178 USE_SAFE_ALLOCA;
4179 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4180 char *class_key = name_key + name_keysize;
4182 /* Start with emacs.FRAMENAME for the name (the specific one)
4183 and with `Emacs' for the class key (the general one). */
4184 char *nz = lispstpcpy (name_key, Vx_resource_name);
4185 char *cz = lispstpcpy (class_key, Vx_resource_class);
4187 *cz++ = '.';
4188 cz = lispstpcpy (cz, class);
4190 if (!NILP (component))
4192 *cz++ = '.';
4193 lispstpcpy (cz, subclass);
4195 *nz++ = '.';
4196 nz = lispstpcpy (nz, component);
4199 *nz++ = '.';
4200 lispstpcpy (nz, attribute);
4202 char *value = x_get_string_resource (rdb, name_key, class_key);
4203 SAFE_FREE();
4205 if (value && *value)
4206 return build_string (value);
4207 else
4208 return Qnil;
4212 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
4213 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
4214 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
4215 class, where INSTANCE is the name under which Emacs was invoked, or
4216 the name specified by the `-name' or `-rn' command-line arguments.
4218 The optional arguments COMPONENT and SUBCLASS add to the key and the
4219 class, respectively. You must specify both of them or neither.
4220 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
4221 and the class is `Emacs.CLASS.SUBCLASS'. */)
4222 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component,
4223 Lisp_Object subclass)
4225 check_window_system (NULL);
4227 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
4228 attribute, class, component, subclass);
4231 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
4233 Lisp_Object
4234 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
4235 Lisp_Object class, Lisp_Object component,
4236 Lisp_Object subclass)
4238 return xrdb_get_resource (dpyinfo->xrdb,
4239 attribute, class, component, subclass);
4242 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
4243 /* Used when C code wants a resource value. */
4244 /* Called from oldXMenu/Create.c. */
4245 char *
4246 x_get_resource_string (const char *attribute, const char *class)
4248 char *result;
4249 struct frame *sf = SELECTED_FRAME ();
4250 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
4251 USE_SAFE_ALLOCA;
4253 /* Allocate space for the components, the dots which separate them,
4254 and the final '\0'. */
4255 ptrdiff_t name_keysize = invocation_namelen + strlen (attribute) + 2;
4256 ptrdiff_t class_keysize = sizeof (EMACS_CLASS) - 1 + strlen (class) + 2;
4257 char *name_key = SAFE_ALLOCA (name_keysize + class_keysize);
4258 char *class_key = name_key + name_keysize;
4260 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
4261 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
4263 result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
4264 name_key, class_key);
4265 SAFE_FREE ();
4266 return result;
4268 #endif
4270 /* Return the value of parameter PARAM.
4272 First search ALIST, then Vdefault_frame_alist, then the X defaults
4273 database, using ATTRIBUTE as the attribute name and CLASS as its class.
4275 Convert the resource to the type specified by desired_type.
4277 If no default is specified, return Qunbound. If you call
4278 x_get_arg, make sure you deal with Qunbound in a reasonable way,
4279 and don't let it get stored in any Lisp-visible variables! */
4281 Lisp_Object
4282 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
4283 const char *attribute, const char *class, enum resource_types type)
4285 Lisp_Object tem;
4287 tem = Fassq (param, alist);
4289 if (!NILP (tem))
4291 /* If we find this parm in ALIST, clear it out
4292 so that it won't be "left over" at the end. */
4293 Lisp_Object tail;
4294 XSETCAR (tem, Qnil);
4295 /* In case the parameter appears more than once in the alist,
4296 clear it out. */
4297 for (tail = alist; CONSP (tail); tail = XCDR (tail))
4298 if (CONSP (XCAR (tail))
4299 && EQ (XCAR (XCAR (tail)), param))
4300 XSETCAR (XCAR (tail), Qnil);
4302 else
4303 tem = Fassq (param, Vdefault_frame_alist);
4305 /* If it wasn't specified in ALIST or the Lisp-level defaults,
4306 look in the X resources. */
4307 if (EQ (tem, Qnil))
4309 if (attribute && dpyinfo)
4311 AUTO_STRING (at, attribute);
4312 AUTO_STRING (cl, class);
4313 tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
4315 if (NILP (tem))
4316 return Qunbound;
4318 switch (type)
4320 case RES_TYPE_NUMBER:
4321 return make_number (atoi (SSDATA (tem)));
4323 case RES_TYPE_BOOLEAN_NUMBER:
4324 if (!strcmp (SSDATA (tem), "on")
4325 || !strcmp (SSDATA (tem), "true"))
4326 return make_number (1);
4327 return make_number (atoi (SSDATA (tem)));
4328 break;
4330 case RES_TYPE_FLOAT:
4331 return make_float (atof (SSDATA (tem)));
4333 case RES_TYPE_BOOLEAN:
4334 tem = Fdowncase (tem);
4335 if (!strcmp (SSDATA (tem), "on")
4336 #ifdef HAVE_NS
4337 || !strcmp (SSDATA (tem), "yes")
4338 #endif
4339 || !strcmp (SSDATA (tem), "true"))
4340 return Qt;
4341 else
4342 return Qnil;
4344 case RES_TYPE_STRING:
4345 return tem;
4347 case RES_TYPE_SYMBOL:
4348 /* As a special case, we map the values `true' and `on'
4349 to Qt, and `false' and `off' to Qnil. */
4351 Lisp_Object lower;
4352 lower = Fdowncase (tem);
4353 if (!strcmp (SSDATA (lower), "on")
4354 #ifdef HAVE_NS
4355 || !strcmp (SSDATA (lower), "yes")
4356 #endif
4357 || !strcmp (SSDATA (lower), "true"))
4358 return Qt;
4359 else if (!strcmp (SSDATA (lower), "off")
4360 #ifdef HAVE_NS
4361 || !strcmp (SSDATA (lower), "no")
4362 #endif
4363 || !strcmp (SSDATA (lower), "false"))
4364 return Qnil;
4365 else
4366 return Fintern (tem, Qnil);
4369 default:
4370 emacs_abort ();
4373 else
4374 return Qunbound;
4376 return Fcdr (tem);
4379 static Lisp_Object
4380 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
4381 const char *attribute, const char *class,
4382 enum resource_types type)
4384 return x_get_arg (FRAME_DISPLAY_INFO (f),
4385 alist, param, attribute, class, type);
4388 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
4390 Lisp_Object
4391 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
4392 Lisp_Object param,
4393 const char *attribute, const char *class,
4394 enum resource_types type)
4396 Lisp_Object value;
4398 value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
4399 attribute, class, type);
4400 if (! NILP (value) && ! EQ (value, Qunbound))
4401 store_frame_param (f, param, value);
4403 return value;
4407 /* Record in frame F the specified or default value according to ALIST
4408 of the parameter named PROP (a Lisp symbol).
4409 If no value is specified for PROP, look for an X default for XPROP
4410 on the frame named NAME.
4411 If that is not found either, use the value DEFLT. */
4413 Lisp_Object
4414 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
4415 Lisp_Object deflt, const char *xprop, const char *xclass,
4416 enum resource_types type)
4418 Lisp_Object tem;
4420 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
4421 if (EQ (tem, Qunbound))
4422 tem = deflt;
4423 AUTO_FRAME_ARG (arg, prop, tem);
4424 x_set_frame_parameters (f, arg);
4425 return tem;
4429 #if !defined (HAVE_X_WINDOWS) && defined (NoValue)
4432 * XParseGeometry parses strings of the form
4433 * "=<width>x<height>{+-}<xoffset>{+-}<yoffset>", where
4434 * width, height, xoffset, and yoffset are unsigned integers.
4435 * Example: "=80x24+300-49"
4436 * The equal sign is optional.
4437 * It returns a bitmask that indicates which of the four values
4438 * were actually found in the string. For each value found,
4439 * the corresponding argument is updated; for each value
4440 * not found, the corresponding argument is left unchanged.
4443 static int
4444 XParseGeometry (char *string,
4445 int *x, int *y,
4446 unsigned int *width, unsigned int *height)
4448 int mask = NoValue;
4449 char *strind;
4450 unsigned long tempWidth, tempHeight;
4451 long int tempX, tempY;
4452 char *nextCharacter;
4454 if (string == NULL || *string == '\0')
4455 return mask;
4456 if (*string == '=')
4457 string++; /* ignore possible '=' at beg of geometry spec */
4459 strind = string;
4460 if (*strind != '+' && *strind != '-' && *strind != 'x')
4462 tempWidth = strtoul (strind, &nextCharacter, 10);
4463 if (strind == nextCharacter)
4464 return 0;
4465 strind = nextCharacter;
4466 mask |= WidthValue;
4469 if (*strind == 'x' || *strind == 'X')
4471 strind++;
4472 tempHeight = strtoul (strind, &nextCharacter, 10);
4473 if (strind == nextCharacter)
4474 return 0;
4475 strind = nextCharacter;
4476 mask |= HeightValue;
4479 if (*strind == '+' || *strind == '-')
4481 if (*strind == '-')
4482 mask |= XNegative;
4483 tempX = strtol (strind, &nextCharacter, 10);
4484 if (strind == nextCharacter)
4485 return 0;
4486 strind = nextCharacter;
4487 mask |= XValue;
4488 if (*strind == '+' || *strind == '-')
4490 if (*strind == '-')
4491 mask |= YNegative;
4492 tempY = strtol (strind, &nextCharacter, 10);
4493 if (strind == nextCharacter)
4494 return 0;
4495 strind = nextCharacter;
4496 mask |= YValue;
4500 /* If strind isn't at the end of the string then it's an invalid
4501 geometry specification. */
4503 if (*strind != '\0')
4504 return 0;
4506 if (mask & XValue)
4507 *x = clip_to_bounds (INT_MIN, tempX, INT_MAX);
4508 if (mask & YValue)
4509 *y = clip_to_bounds (INT_MIN, tempY, INT_MAX);
4510 if (mask & WidthValue)
4511 *width = min (tempWidth, UINT_MAX);
4512 if (mask & HeightValue)
4513 *height = min (tempHeight, UINT_MAX);
4514 return mask;
4517 #endif /* !defined (HAVE_X_WINDOWS) && defined (NoValue) */
4520 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4521 make-docfile: the documentation string in ns-win.el was used for
4522 x-parse-geometry even in non-NS builds.
4524 With two definitions of x-parse-geometry in this file, various
4525 things still get confused (eg M-x apropos documentation), so that
4526 it is best if the two definitions just share the same doc-string.
4528 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4529 doc: /* Parse a display geometry string STRING.
4530 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4531 The properties returned may include `top', `left', `height', and `width'.
4532 For X, the value of `left' or `top' may be an integer,
4533 or a list (+ N) meaning N pixels relative to top/left corner,
4534 or a list (- N) meaning -N pixels relative to bottom/right corner.
4535 On Nextstep, this just calls `ns-parse-geometry'. */)
4536 (Lisp_Object string)
4538 int geometry, x, y;
4539 unsigned int width, height;
4540 Lisp_Object result;
4542 CHECK_STRING (string);
4544 #ifdef HAVE_NS
4545 if (strchr (SSDATA (string), ' ') != NULL)
4546 return call1 (Qns_parse_geometry, string);
4547 #endif
4548 geometry = XParseGeometry (SSDATA (string),
4549 &x, &y, &width, &height);
4550 result = Qnil;
4551 if (geometry & XValue)
4553 Lisp_Object element;
4555 if (x >= 0 && (geometry & XNegative))
4556 element = list3 (Qleft, Qminus, make_number (-x));
4557 else if (x < 0 && ! (geometry & XNegative))
4558 element = list3 (Qleft, Qplus, make_number (x));
4559 else
4560 element = Fcons (Qleft, make_number (x));
4561 result = Fcons (element, result);
4564 if (geometry & YValue)
4566 Lisp_Object element;
4568 if (y >= 0 && (geometry & YNegative))
4569 element = list3 (Qtop, Qminus, make_number (-y));
4570 else if (y < 0 && ! (geometry & YNegative))
4571 element = list3 (Qtop, Qplus, make_number (y));
4572 else
4573 element = Fcons (Qtop, make_number (y));
4574 result = Fcons (element, result);
4577 if (geometry & WidthValue)
4578 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4579 if (geometry & HeightValue)
4580 result = Fcons (Fcons (Qheight, make_number (height)), result);
4582 return result;
4586 /* Calculate the desired size and position of frame F.
4587 Return the flags saying which aspects were specified.
4589 Also set the win_gravity and size_hint_flags of F.
4591 Adjust height for toolbar if TOOLBAR_P is 1.
4593 This function does not make the coordinates positive. */
4595 #define DEFAULT_ROWS 36
4596 #define DEFAULT_COLS 80
4598 long
4599 x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
4601 Lisp_Object height, width, user_size, top, left, user_position;
4602 long window_prompting = 0;
4603 Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
4605 /* Default values if we fall through.
4606 Actually, if that happens we should get
4607 window manager prompting. */
4608 SET_FRAME_WIDTH (f, DEFAULT_COLS * FRAME_COLUMN_WIDTH (f));
4609 SET_FRAME_COLS (f, DEFAULT_COLS);
4610 SET_FRAME_HEIGHT (f, DEFAULT_ROWS * FRAME_LINE_HEIGHT (f));
4611 SET_FRAME_LINES (f, DEFAULT_ROWS);
4613 /* Window managers expect that if program-specified
4614 positions are not (0,0), they're intentional, not defaults. */
4615 f->top_pos = 0;
4616 f->left_pos = 0;
4618 /* Calculate a tool bar height so that the user gets a text display
4619 area of the size he specified with -g or via .Xdefaults. Later
4620 changes of the tool bar height don't change the frame size. This
4621 is done so that users can create tall Emacs frames without having
4622 to guess how tall the tool bar will get. */
4623 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4625 if (frame_default_tool_bar_height)
4626 FRAME_TOOL_BAR_HEIGHT (f) = frame_default_tool_bar_height;
4627 else
4629 int margin, relief;
4631 relief = (tool_bar_button_relief >= 0
4632 ? tool_bar_button_relief
4633 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4635 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4636 margin = XFASTINT (Vtool_bar_button_margin);
4637 else if (CONSP (Vtool_bar_button_margin)
4638 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4639 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4640 else
4641 margin = 0;
4643 FRAME_TOOL_BAR_HEIGHT (f)
4644 = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4648 /* Ensure that earlier new_width and new_height settings won't
4649 override what we specify below. */
4650 f->new_width = f->new_height = 0;
4652 height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4653 width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4654 if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
4656 if (!EQ (width, Qunbound))
4658 if (CONSP (width) && EQ (XCAR (width), Qtext_pixels))
4660 CHECK_NUMBER (XCDR (width));
4661 if ((XINT (XCDR (width)) < 0 || XINT (XCDR (width)) > INT_MAX))
4662 xsignal1 (Qargs_out_of_range, XCDR (width));
4664 SET_FRAME_WIDTH (f, XINT (XCDR (width)));
4665 f->inhibit_horizontal_resize = true;
4666 *x_width = XINT (XCDR (width));
4668 else
4670 CHECK_NUMBER (width);
4671 if ((XINT (width) < 0 || XINT (width) > INT_MAX))
4672 xsignal1 (Qargs_out_of_range, width);
4674 SET_FRAME_WIDTH (f, XINT (width) * FRAME_COLUMN_WIDTH (f));
4678 if (!EQ (height, Qunbound))
4680 if (CONSP (height) && EQ (XCAR (height), Qtext_pixels))
4682 CHECK_NUMBER (XCDR (height));
4683 if ((XINT (XCDR (height)) < 0 || XINT (XCDR (height)) > INT_MAX))
4684 xsignal1 (Qargs_out_of_range, XCDR (height));
4686 SET_FRAME_HEIGHT (f, XINT (XCDR (height)));
4687 f->inhibit_vertical_resize = true;
4688 *x_height = XINT (XCDR (height));
4690 else
4692 CHECK_NUMBER (height);
4693 if ((XINT (height) < 0) || (XINT (height) > INT_MAX))
4694 xsignal1 (Qargs_out_of_range, height);
4696 SET_FRAME_HEIGHT (f, XINT (height) * FRAME_LINE_HEIGHT (f));
4700 user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4701 if (!NILP (user_size) && !EQ (user_size, Qunbound))
4702 window_prompting |= USSize;
4703 else
4704 window_prompting |= PSize;
4707 top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4708 left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4709 user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4710 if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
4712 if (EQ (top, Qminus))
4714 f->top_pos = 0;
4715 window_prompting |= YNegative;
4717 else if (CONSP (top) && EQ (XCAR (top), Qminus)
4718 && CONSP (XCDR (top))
4719 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
4721 f->top_pos = - XINT (XCAR (XCDR (top)));
4722 window_prompting |= YNegative;
4724 else if (CONSP (top) && EQ (XCAR (top), Qplus)
4725 && CONSP (XCDR (top))
4726 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
4728 f->top_pos = XINT (XCAR (XCDR (top)));
4730 else if (EQ (top, Qunbound))
4731 f->top_pos = 0;
4732 else
4734 CHECK_TYPE_RANGED_INTEGER (int, top);
4735 f->top_pos = XINT (top);
4736 if (f->top_pos < 0)
4737 window_prompting |= YNegative;
4740 if (EQ (left, Qminus))
4742 f->left_pos = 0;
4743 window_prompting |= XNegative;
4745 else if (CONSP (left) && EQ (XCAR (left), Qminus)
4746 && CONSP (XCDR (left))
4747 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
4749 f->left_pos = - XINT (XCAR (XCDR (left)));
4750 window_prompting |= XNegative;
4752 else if (CONSP (left) && EQ (XCAR (left), Qplus)
4753 && CONSP (XCDR (left))
4754 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
4756 f->left_pos = XINT (XCAR (XCDR (left)));
4758 else if (EQ (left, Qunbound))
4759 f->left_pos = 0;
4760 else
4762 CHECK_TYPE_RANGED_INTEGER (int, left);
4763 f->left_pos = XINT (left);
4764 if (f->left_pos < 0)
4765 window_prompting |= XNegative;
4768 if (!NILP (user_position) && ! EQ (user_position, Qunbound))
4769 window_prompting |= USPosition;
4770 else
4771 window_prompting |= PPosition;
4774 if (window_prompting & XNegative)
4776 if (window_prompting & YNegative)
4777 f->win_gravity = SouthEastGravity;
4778 else
4779 f->win_gravity = NorthEastGravity;
4781 else
4783 if (window_prompting & YNegative)
4784 f->win_gravity = SouthWestGravity;
4785 else
4786 f->win_gravity = NorthWestGravity;
4789 f->size_hint_flags = window_prompting;
4791 return window_prompting;
4796 #endif /* HAVE_WINDOW_SYSTEM */
4798 void
4799 frame_make_pointer_invisible (struct frame *f)
4801 if (! NILP (Vmake_pointer_invisible))
4803 if (f && FRAME_LIVE_P (f) && !f->pointer_invisible
4804 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4806 f->mouse_moved = 0;
4807 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4808 f->pointer_invisible = 1;
4813 void
4814 frame_make_pointer_visible (struct frame *f)
4816 /* We don't check Vmake_pointer_invisible here in case the
4817 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4818 if (f && FRAME_LIVE_P (f) && f->pointer_invisible && f->mouse_moved
4819 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4821 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4822 f->pointer_invisible = 0;
4826 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4827 Sframe_pointer_visible_p, 0, 1, 0,
4828 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4829 Otherwise it returns nil. FRAME omitted or nil means the
4830 selected frame. This is useful when `make-pointer-invisible' is set. */)
4831 (Lisp_Object frame)
4833 return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
4838 /***********************************************************************
4839 Multimonitor data
4840 ***********************************************************************/
4842 #ifdef HAVE_WINDOW_SYSTEM
4844 # if (defined HAVE_NS \
4845 || (!defined USE_GTK && (defined HAVE_XINERAMA || defined HAVE_XRANDR)))
4846 void
4847 free_monitors (struct MonitorInfo *monitors, int n_monitors)
4849 int i;
4850 for (i = 0; i < n_monitors; ++i)
4851 xfree (monitors[i].name);
4852 xfree (monitors);
4854 # endif
4856 Lisp_Object
4857 make_monitor_attribute_list (struct MonitorInfo *monitors,
4858 int n_monitors,
4859 int primary_monitor,
4860 Lisp_Object monitor_frames,
4861 const char *source)
4863 Lisp_Object attributes_list = Qnil;
4864 Lisp_Object primary_monitor_attributes = Qnil;
4865 int i;
4867 for (i = 0; i < n_monitors; ++i)
4869 Lisp_Object geometry, workarea, attributes = Qnil;
4870 struct MonitorInfo *mi = &monitors[i];
4872 if (mi->geom.width == 0) continue;
4874 workarea = list4i (mi->work.x, mi->work.y,
4875 mi->work.width, mi->work.height);
4876 geometry = list4i (mi->geom.x, mi->geom.y,
4877 mi->geom.width, mi->geom.height);
4878 attributes = Fcons (Fcons (Qsource, build_string (source)),
4879 attributes);
4880 attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
4881 attributes);
4882 attributes = Fcons (Fcons (Qmm_size,
4883 list2i (mi->mm_width, mi->mm_height)),
4884 attributes);
4885 attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
4886 attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
4887 if (mi->name)
4888 attributes = Fcons (Fcons (Qname, make_string (mi->name,
4889 strlen (mi->name))),
4890 attributes);
4892 if (i == primary_monitor)
4893 primary_monitor_attributes = attributes;
4894 else
4895 attributes_list = Fcons (attributes, attributes_list);
4898 if (!NILP (primary_monitor_attributes))
4899 attributes_list = Fcons (primary_monitor_attributes, attributes_list);
4900 return attributes_list;
4903 #endif /* HAVE_WINDOW_SYSTEM */
4906 /***********************************************************************
4907 Initialization
4908 ***********************************************************************/
4910 void
4911 syms_of_frame (void)
4913 DEFSYM (Qframep, "framep");
4914 DEFSYM (Qframe_live_p, "frame-live-p");
4915 DEFSYM (Qframe_windows_min_size, "frame-windows-min-size");
4916 DEFSYM (Qwindow__pixel_to_total, "window--pixel-to-total");
4917 DEFSYM (Qexplicit_name, "explicit-name");
4918 DEFSYM (Qheight, "height");
4919 DEFSYM (Qicon, "icon");
4920 DEFSYM (Qminibuffer, "minibuffer");
4921 DEFSYM (Qmodeline, "modeline");
4922 DEFSYM (Qonly, "only");
4923 DEFSYM (Qnone, "none");
4924 DEFSYM (Qwidth, "width");
4925 DEFSYM (Qtext_pixels, "text-pixels");
4926 DEFSYM (Qgeometry, "geometry");
4927 DEFSYM (Qicon_left, "icon-left");
4928 DEFSYM (Qicon_top, "icon-top");
4929 DEFSYM (Qtooltip, "tooltip");
4930 DEFSYM (Quser_position, "user-position");
4931 DEFSYM (Quser_size, "user-size");
4932 DEFSYM (Qwindow_id, "window-id");
4933 #ifdef HAVE_X_WINDOWS
4934 DEFSYM (Qouter_window_id, "outer-window-id");
4935 #endif
4936 DEFSYM (Qparent_id, "parent-id");
4937 DEFSYM (Qx, "x");
4938 DEFSYM (Qw32, "w32");
4939 DEFSYM (Qpc, "pc");
4940 DEFSYM (Qns, "ns");
4941 DEFSYM (Qvisible, "visible");
4942 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4943 DEFSYM (Qbuffer_list, "buffer-list");
4944 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4945 DEFSYM (Qdisplay_type, "display-type");
4946 DEFSYM (Qbackground_mode, "background-mode");
4947 DEFSYM (Qnoelisp, "noelisp");
4948 DEFSYM (Qtty_color_mode, "tty-color-mode");
4949 DEFSYM (Qtty, "tty");
4950 DEFSYM (Qtty_type, "tty-type");
4952 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4954 DEFSYM (Qfullwidth, "fullwidth");
4955 DEFSYM (Qfullheight, "fullheight");
4956 DEFSYM (Qfullboth, "fullboth");
4957 DEFSYM (Qmaximized, "maximized");
4958 DEFSYM (Qx_resource_name, "x-resource-name");
4959 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4961 DEFSYM (Qterminal, "terminal");
4963 DEFSYM (Qworkarea, "workarea");
4964 DEFSYM (Qmm_size, "mm-size");
4965 DEFSYM (Qframes, "frames");
4966 DEFSYM (Qsource, "source");
4968 DEFSYM (Qouter_edges, "outer-edges");
4969 DEFSYM (Qouter_position, "outer-position");
4970 DEFSYM (Qouter_size, "outer-size");
4971 DEFSYM (Qnative_edges, "native-edges");
4972 DEFSYM (Qinner_edges, "inner-edges");
4973 DEFSYM (Qexternal_border_size, "external-border-size");
4974 DEFSYM (Qtitle_bar_size, "title-bar-size");
4975 DEFSYM (Qmenu_bar_external, "menu-bar-external");
4976 DEFSYM (Qmenu_bar_size, "menu-bar-size");
4977 DEFSYM (Qtool_bar_external, "tool-bar-external");
4978 DEFSYM (Qtool_bar_size, "tool-bar-size");
4979 /* The following are used for frame_size_history. */
4980 DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
4981 DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
4982 DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
4983 DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
4984 DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
4985 DEFSYM (Qset_frame_size, "set-frame-size");
4986 DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
4987 DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
4988 DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
4989 DEFSYM (Qxg_frame_resized, "xg-frame-resized");
4990 DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
4991 DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
4992 DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
4993 DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
4994 DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
4995 DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
4996 DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
4997 DEFSYM (Qx_net_wm_state, "x-net-wm-state");
4998 DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
4999 DEFSYM (Qtb_size_cb, "tb-size-cb");
5000 DEFSYM (Qupdate_frame_tool_bar, "update-frame-tool-bar");
5001 DEFSYM (Qfree_frame_tool_bar, "free-frame-tool-bar");
5002 DEFSYM (Qx_set_menu_bar_lines, "x-set-menu-bar-lines");
5003 DEFSYM (Qchange_frame_size, "change-frame-size");
5004 DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
5005 DEFSYM (Qset_window_configuration, "set-window-configuration");
5006 DEFSYM (Qx_create_frame_1, "x-create-frame-1");
5007 DEFSYM (Qx_create_frame_2, "x-create-frame-2");
5008 DEFSYM (Qterminal_frame, "terminal-frame");
5010 #ifdef HAVE_NS
5011 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
5012 #endif
5014 DEFSYM (Qalpha, "alpha");
5015 DEFSYM (Qauto_lower, "auto-lower");
5016 DEFSYM (Qauto_raise, "auto-raise");
5017 DEFSYM (Qborder_color, "border-color");
5018 DEFSYM (Qborder_width, "border-width");
5019 DEFSYM (Qbottom_divider_width, "bottom-divider-width");
5020 DEFSYM (Qcursor_color, "cursor-color");
5021 DEFSYM (Qcursor_type, "cursor-type");
5022 DEFSYM (Qfont_backend, "font-backend");
5023 DEFSYM (Qfullscreen, "fullscreen");
5024 DEFSYM (Qhorizontal_scroll_bars, "horizontal-scroll-bars");
5025 DEFSYM (Qicon_name, "icon-name");
5026 DEFSYM (Qicon_type, "icon-type");
5027 DEFSYM (Qinternal_border_width, "internal-border-width");
5028 DEFSYM (Qleft_fringe, "left-fringe");
5029 DEFSYM (Qline_spacing, "line-spacing");
5030 DEFSYM (Qmenu_bar_lines, "menu-bar-lines");
5031 DEFSYM (Qupdate_frame_menubar, "update-frame-menubar");
5032 DEFSYM (Qfree_frame_menubar_1, "free-frame-menubar-1");
5033 DEFSYM (Qfree_frame_menubar_2, "free-frame-menubar-2");
5034 DEFSYM (Qmouse_color, "mouse-color");
5035 DEFSYM (Qname, "name");
5036 DEFSYM (Qright_divider_width, "right-divider-width");
5037 DEFSYM (Qright_fringe, "right-fringe");
5038 DEFSYM (Qscreen_gamma, "screen-gamma");
5039 DEFSYM (Qscroll_bar_background, "scroll-bar-background");
5040 DEFSYM (Qscroll_bar_foreground, "scroll-bar-foreground");
5041 DEFSYM (Qscroll_bar_height, "scroll-bar-height");
5042 DEFSYM (Qscroll_bar_width, "scroll-bar-width");
5043 DEFSYM (Qsticky, "sticky");
5044 DEFSYM (Qtitle, "title");
5045 DEFSYM (Qtool_bar_lines, "tool-bar-lines");
5046 DEFSYM (Qtool_bar_position, "tool-bar-position");
5047 DEFSYM (Qunsplittable, "unsplittable");
5048 DEFSYM (Qvertical_scroll_bars, "vertical-scroll-bars");
5049 DEFSYM (Qvisibility, "visibility");
5050 DEFSYM (Qwait_for_wm, "wait-for-wm");
5053 int i;
5055 for (i = 0; i < ARRAYELTS (frame_parms); i++)
5057 Lisp_Object v = (frame_parms[i].sym < 0
5058 ? intern_c_string (frame_parms[i].name)
5059 : builtin_lisp_symbol (frame_parms[i].sym));
5060 Fput (v, Qx_frame_parameter, make_number (i));
5064 #ifdef HAVE_WINDOW_SYSTEM
5065 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
5066 doc: /* The name Emacs uses to look up X resources.
5067 `x-get-resource' uses this as the first component of the instance name
5068 when requesting resource values.
5069 Emacs initially sets `x-resource-name' to the name under which Emacs
5070 was invoked, or to the value specified with the `-name' or `-rn'
5071 switches, if present.
5073 It may be useful to bind this variable locally around a call
5074 to `x-get-resource'. See also the variable `x-resource-class'. */);
5075 Vx_resource_name = Qnil;
5077 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
5078 doc: /* The class Emacs uses to look up X resources.
5079 `x-get-resource' uses this as the first component of the instance class
5080 when requesting resource values.
5082 Emacs initially sets `x-resource-class' to "Emacs".
5084 Setting this variable permanently is not a reasonable thing to do,
5085 but binding this variable locally around a call to `x-get-resource'
5086 is a reasonable practice. See also the variable `x-resource-name'. */);
5087 Vx_resource_class = build_string (EMACS_CLASS);
5089 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
5090 doc: /* The lower limit of the frame opacity (alpha transparency).
5091 The value should range from 0 (invisible) to 100 (completely opaque).
5092 You can also use a floating number between 0.0 and 1.0. */);
5093 Vframe_alpha_lower_limit = make_number (20);
5094 #endif
5096 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
5097 doc: /* Alist of default values for frame creation.
5098 These may be set in your init file, like this:
5099 (setq default-frame-alist \\='((width . 80) (height . 55) (menu-bar-lines . 1)))
5100 These override values given in window system configuration data,
5101 including X Windows' defaults database.
5102 For values specific to the first Emacs frame, see `initial-frame-alist'.
5103 For window-system specific values, see `window-system-default-frame-alist'.
5104 For values specific to the separate minibuffer frame, see
5105 `minibuffer-frame-alist'.
5106 The `menu-bar-lines' element of the list controls whether new frames
5107 have menu bars; `menu-bar-mode' works by altering this element.
5108 Setting this variable does not affect existing frames, only new ones. */);
5109 Vdefault_frame_alist = Qnil;
5111 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
5112 doc: /* Default position of vertical scroll bars on this window-system. */);
5113 #ifdef HAVE_WINDOW_SYSTEM
5114 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
5115 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
5116 default. */
5117 Vdefault_frame_scroll_bars = Qright;
5118 #else
5119 Vdefault_frame_scroll_bars = Qleft;
5120 #endif
5121 #else
5122 Vdefault_frame_scroll_bars = Qnil;
5123 #endif
5125 DEFVAR_BOOL ("scroll-bar-adjust-thumb-portion",
5126 scroll_bar_adjust_thumb_portion_p,
5127 doc: /* Adjust thumb for overscrolling for Gtk+ and MOTIF.
5128 Non-nil means adjust the thumb in the scroll bar so it can be dragged downwards
5129 even if the end of the buffer is shown (i.e. overscrolling).
5130 Set to nil if you want the thumb to be at the bottom when the end of the buffer
5131 is shown. Also, the thumb fills the whole scroll bar when the entire buffer
5132 is visible. In this case you can not overscroll. */);
5133 scroll_bar_adjust_thumb_portion_p = 1;
5135 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
5136 doc: /* The initial frame-object, which represents Emacs's stdout. */);
5138 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
5139 doc: /* If non-nil, function to transform normal value of `mouse-position'.
5140 `mouse-position' and `mouse-pixel-position' call this function, passing their
5141 usual return value as argument, and return whatever this function returns.
5142 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
5143 which need to do mouse handling at the Lisp level. */);
5144 Vmouse_position_function = Qnil;
5146 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
5147 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
5148 If the value is an integer, highlighting is only shown after moving the
5149 mouse, while keyboard input turns off the highlight even when the mouse
5150 is over the clickable text. However, the mouse shape still indicates
5151 when the mouse is over clickable text. */);
5152 Vmouse_highlight = Qt;
5154 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
5155 doc: /* If non-nil, make pointer invisible while typing.
5156 The pointer becomes visible again when the mouse is moved. */);
5157 Vmake_pointer_invisible = Qt;
5159 DEFVAR_LISP ("focus-in-hook", Vfocus_in_hook,
5160 doc: /* Normal hook run when a frame gains input focus. */);
5161 Vfocus_in_hook = Qnil;
5163 DEFVAR_LISP ("focus-out-hook", Vfocus_out_hook,
5164 doc: /* Normal hook run when a frame loses input focus. */);
5165 Vfocus_out_hook = Qnil;
5167 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
5168 doc: /* Functions run before deleting a frame.
5169 The functions are run with one arg, the frame to be deleted.
5170 See `delete-frame'.
5172 Note that functions in this list may be called just before the frame is
5173 actually deleted, or some time later (or even both when an earlier function
5174 in `delete-frame-functions' (indirectly) calls `delete-frame'
5175 recursively). */);
5176 Vdelete_frame_functions = Qnil;
5177 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
5179 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
5180 doc: /* Non-nil if Menu-Bar mode is enabled.
5181 See the command `menu-bar-mode' for a description of this minor mode.
5182 Setting this variable directly does not take effect;
5183 either customize it (see the info node `Easy Customization')
5184 or call the function `menu-bar-mode'. */);
5185 Vmenu_bar_mode = Qt;
5187 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
5188 doc: /* Non-nil if Tool-Bar mode is enabled.
5189 See the command `tool-bar-mode' for a description of this minor mode.
5190 Setting this variable directly does not take effect;
5191 either customize it (see the info node `Easy Customization')
5192 or call the function `tool-bar-mode'. */);
5193 #ifdef HAVE_WINDOW_SYSTEM
5194 Vtool_bar_mode = Qt;
5195 #else
5196 Vtool_bar_mode = Qnil;
5197 #endif
5199 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
5200 doc: /* Minibufferless frames use this frame's minibuffer.
5201 Emacs cannot create minibufferless frames unless this is set to an
5202 appropriate surrogate.
5204 Emacs consults this variable only when creating minibufferless
5205 frames; once the frame is created, it sticks with its assigned
5206 minibuffer, no matter what this variable is set to. This means that
5207 this variable doesn't necessarily say anything meaningful about the
5208 current set of frames, or where the minibuffer is currently being
5209 displayed.
5211 This variable is local to the current terminal and cannot be buffer-local. */);
5213 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
5214 doc: /* Non-nil if window system changes focus when you move the mouse.
5215 You should set this variable to tell Emacs how your window manager
5216 handles focus, since there is no way in general for Emacs to find out
5217 automatically. See also `mouse-autoselect-window'. */);
5218 focus_follows_mouse = 0;
5220 DEFVAR_BOOL ("frame-resize-pixelwise", frame_resize_pixelwise,
5221 doc: /* Non-nil means resize frames pixelwise.
5222 If this option is nil, resizing a frame rounds its sizes to the frame's
5223 current values of `frame-char-height' and `frame-char-width'. If this
5224 is non-nil, no rounding occurs, hence frame sizes can increase/decrease
5225 by one pixel.
5227 With some window managers you may have to set this to non-nil in order
5228 to set the size of a frame in pixels, to maximize frames or to make them
5229 fullscreen. To resize your initial frame pixelwise, set this option to
5230 a non-nil value in your init file. */);
5231 frame_resize_pixelwise = 0;
5233 DEFVAR_LISP ("frame-inhibit-implied-resize", frame_inhibit_implied_resize,
5234 doc: /* Whether frames should be resized implicitly.
5235 If this option is nil, setting font, menu bar, tool bar, internal
5236 borders, fringes or scroll bars of a specific frame may resize the frame
5237 in order to preserve the number of columns or lines it displays. If
5238 this option is t, no such resizing is done. Note that the size of
5239 fullscreen and maximized frames, the height of fullheight frames and the
5240 width of fullwidth frames never change implicitly.
5242 The value of this option can be also be a list of frame parameters. In
5243 this case, resizing is inhibited when changing a parameter that appears
5244 in that list. The parameters currently handled by this option include
5245 `font', `font-backend', `internal-border-width', `menu-bar-lines' and
5246 `tool-bar-lines'.
5248 Changing any of the parameters `scroll-bar-width', `scroll-bar-height',
5249 `vertical-scroll-bars', `horizontal-scroll-bars', `left-fringe' and
5250 `right-fringe' is handled as if the frame contained just one live
5251 window. This means, for example, that removing vertical scroll bars on
5252 a frame containing several side by side windows will shrink the frame
5253 width by the width of one scroll bar provided this option is nil and
5254 keep it unchanged if this option is either t or a list containing
5255 `vertical-scroll-bars'.
5257 The default value is \\='(tool-bar-lines) on Lucid, Motif and Windows
5258 \(which means that adding/removing a tool bar does not change the frame
5259 height), nil on all other window systems including GTK+ (which means
5260 that changing any of the parameters listed above may change the size of
5261 the frame), and t otherwise (which means the frame size never changes
5262 implicitly when there's no window system support).
5264 Note that when a frame is not large enough to accommodate a change of
5265 any of the parameters listed above, Emacs may try to enlarge the frame
5266 even if this option is non-nil. */);
5267 #if defined (HAVE_WINDOW_SYSTEM)
5268 #if defined (USE_LUCID) || defined (USE_MOTIF) || defined (HAVE_NTGUI)
5269 frame_inhibit_implied_resize = list1 (Qtool_bar_lines);
5270 #else
5271 frame_inhibit_implied_resize = Qnil;
5272 #endif
5273 #else
5274 frame_inhibit_implied_resize = Qt;
5275 #endif
5277 DEFVAR_LISP ("frame-size-history", frame_size_history,
5278 doc: /* History of frame size adjustments.
5279 If non-nil, list recording frame size adjustment. Adjustments are
5280 recorded only if the first element of this list is a positive number.
5281 Adding an adjustment decrements that number by one.
5283 The remaining elements are the adjustments. Each adjustment is a list
5284 of four elements `frame', `function', `sizes' and `more'. `frame' is
5285 the affected frame and `function' the invoking function. `sizes' is
5286 usually a list of four elements `old-width', `old-height', `new-width'
5287 and `new-height' representing the old and new sizes recorded/requested
5288 by `function'. `more' is a list with additional information.
5290 The function `frame--size-history' displays the value of this variable
5291 in a more readable form. */);
5292 frame_size_history = Qnil;
5294 DEFVAR_BOOL ("tooltip-reuse-hidden-frame", tooltip_reuse_hidden_frame,
5295 doc: /* Non-nil means reuse hidden tooltip frames.
5296 When this is nil, delete a tooltip frame when hiding the associated
5297 tooltip. When this is non-nil, make the tooltip frame invisible only,
5298 so it can be reused when the next tooltip is shown.
5300 Setting this to non-nil may drastically reduce the consing overhead
5301 incurred by creating new tooltip frames. However, a value of non-nil
5302 means also that intermittent changes of faces or `default-frame-alist'
5303 are not applied when showing a tooltip in a reused frame.
5305 This variable is effective only with the X toolkit (and there only when
5306 Gtk+ tooltips are not used) and on Windows. */);
5307 tooltip_reuse_hidden_frame = false;
5309 staticpro (&Vframe_list);
5311 defsubr (&Sframep);
5312 defsubr (&Sframe_live_p);
5313 defsubr (&Swindow_system);
5314 defsubr (&Sframe_windows_min_size);
5315 defsubr (&Smake_terminal_frame);
5316 defsubr (&Shandle_switch_frame);
5317 defsubr (&Sselect_frame);
5318 defsubr (&Sselected_frame);
5319 defsubr (&Sframe_list);
5320 defsubr (&Snext_frame);
5321 defsubr (&Sprevious_frame);
5322 defsubr (&Slast_nonminibuf_frame);
5323 defsubr (&Sdelete_frame);
5324 defsubr (&Smouse_position);
5325 defsubr (&Smouse_pixel_position);
5326 defsubr (&Sset_mouse_position);
5327 defsubr (&Sset_mouse_pixel_position);
5328 #if 0
5329 defsubr (&Sframe_configuration);
5330 defsubr (&Srestore_frame_configuration);
5331 #endif
5332 defsubr (&Smake_frame_visible);
5333 defsubr (&Smake_frame_invisible);
5334 defsubr (&Siconify_frame);
5335 defsubr (&Sframe_visible_p);
5336 defsubr (&Svisible_frame_list);
5337 defsubr (&Sraise_frame);
5338 defsubr (&Slower_frame);
5339 defsubr (&Sx_focus_frame);
5340 defsubr (&Sframe_after_make_frame);
5341 defsubr (&Sredirect_frame_focus);
5342 defsubr (&Sframe_focus);
5343 defsubr (&Sframe_parameters);
5344 defsubr (&Sframe_parameter);
5345 defsubr (&Smodify_frame_parameters);
5346 defsubr (&Sframe_char_height);
5347 defsubr (&Sframe_char_width);
5348 defsubr (&Sframe_pixel_height);
5349 defsubr (&Sframe_pixel_width);
5350 defsubr (&Sframe_text_cols);
5351 defsubr (&Sframe_text_lines);
5352 defsubr (&Sframe_total_cols);
5353 defsubr (&Sframe_total_lines);
5354 defsubr (&Sframe_text_width);
5355 defsubr (&Sframe_text_height);
5356 defsubr (&Sscroll_bar_width);
5357 defsubr (&Sscroll_bar_height);
5358 defsubr (&Sfringe_width);
5359 defsubr (&Sborder_width);
5360 defsubr (&Sright_divider_width);
5361 defsubr (&Sbottom_divider_width);
5362 defsubr (&Stool_bar_pixel_width);
5363 defsubr (&Sset_frame_height);
5364 defsubr (&Sset_frame_width);
5365 defsubr (&Sset_frame_size);
5366 defsubr (&Sframe_position);
5367 defsubr (&Sset_frame_position);
5368 defsubr (&Sframe_pointer_visible_p);
5370 #ifdef HAVE_WINDOW_SYSTEM
5371 defsubr (&Sx_get_resource);
5372 defsubr (&Sx_parse_geometry);
5373 #endif