Merge from trunk.
[emacs.git] / src / frame.c
blob8b28543728836f091747e8bd1df3455a01f33e66
1 /* Generic frame functions.
3 Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #include <config.h>
22 #include <stdio.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <limits.h>
26 #include <setjmp.h>
27 #include "lisp.h"
28 #include "character.h"
29 #ifdef HAVE_X_WINDOWS
30 #include "xterm.h"
31 #endif
32 #ifdef WINDOWSNT
33 #include "w32term.h"
34 #endif
35 #ifdef HAVE_NS
36 #include "nsterm.h"
37 #endif
38 #include "buffer.h"
39 /* These help us bind and responding to switch-frame events. */
40 #include "commands.h"
41 #include "keyboard.h"
42 #include "frame.h"
43 #include "blockinput.h"
44 #include "termchar.h"
45 #include "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #include "font.h"
49 #ifdef HAVE_WINDOW_SYSTEM
50 #include "fontset.h"
51 #endif
52 #ifdef MSDOS
53 #include "msdos.h"
54 #include "dosfns.h"
55 #endif
58 #ifdef HAVE_WINDOW_SYSTEM
60 #endif
62 #ifdef HAVE_NS
63 Lisp_Object Qns_parse_geometry;
64 #endif
66 Lisp_Object Qframep, Qframe_live_p;
67 Lisp_Object Qicon, Qmodeline;
68 Lisp_Object Qonly;
69 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
70 Lisp_Object Qvisible;
71 Lisp_Object Qdisplay_type;
72 static Lisp_Object Qbackground_mode;
73 Lisp_Object Qnoelisp;
75 static Lisp_Object Qx_frame_parameter;
76 Lisp_Object Qx_resource_name;
77 Lisp_Object Qterminal;
78 Lisp_Object Qterminal_live_p;
80 /* Frame parameters (set or reported). */
82 Lisp_Object Qauto_raise, Qauto_lower;
83 Lisp_Object Qborder_color, Qborder_width;
84 Lisp_Object Qcursor_color, Qcursor_type;
85 static Lisp_Object Qgeometry; /* Not used */
86 Lisp_Object Qheight, Qwidth;
87 Lisp_Object Qleft, Qright;
88 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
89 Lisp_Object Qtooltip;
90 Lisp_Object Qinternal_border_width;
91 Lisp_Object Qmouse_color;
92 Lisp_Object Qminibuffer;
93 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
94 Lisp_Object Qvisibility;
95 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
96 Lisp_Object Qscreen_gamma;
97 Lisp_Object Qline_spacing;
98 static Lisp_Object Quser_position, Quser_size;
99 Lisp_Object Qwait_for_wm;
100 static Lisp_Object Qwindow_id;
101 #ifdef HAVE_X_WINDOWS
102 static Lisp_Object Qouter_window_id;
103 #endif
104 Lisp_Object Qparent_id;
105 Lisp_Object Qtitle, Qname;
106 static Lisp_Object Qexplicit_name;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate;
111 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
112 Lisp_Object Qtty_color_mode;
113 Lisp_Object Qtty, Qtty_type;
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
116 Lisp_Object Qsticky;
117 Lisp_Object Qfont_backend;
118 Lisp_Object Qalpha;
120 Lisp_Object Qface_set_after_frame_default;
122 static Lisp_Object Qdelete_frame_functions;
124 #ifdef HAVE_WINDOW_SYSTEM
125 static void x_report_frame_params (struct frame *, Lisp_Object *);
126 #endif
129 static void
130 set_menu_bar_lines_1 (Lisp_Object window, int n)
132 struct window *w = XWINDOW (window);
134 XSETFASTINT (w->last_modified, 0);
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
138 /* Handle just the top child in a vertical split. */
139 if (!NILP (w->vchild))
140 set_menu_bar_lines_1 (w->vchild, n);
142 /* Adjust all children in a horizontal split. */
143 for (window = w->hchild; !NILP (window); window = w->next)
145 w = XWINDOW (window);
146 set_menu_bar_lines_1 (window, n);
150 void
151 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
153 int nlines;
154 int olines = FRAME_MENU_BAR_LINES (f);
156 /* Right now, menu bars don't work properly in minibuf-only frames;
157 most of the commands try to apply themselves to the minibuffer
158 frame itself, and get an error because you can't switch buffers
159 in or split the minibuffer window. */
160 if (FRAME_MINIBUF_ONLY_P (f))
161 return;
163 if (TYPE_RANGED_INTEGERP (int, value))
164 nlines = XINT (value);
165 else
166 nlines = 0;
168 if (nlines != olines)
170 windows_or_buffers_changed++;
171 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
172 FRAME_MENU_BAR_LINES (f) = nlines;
173 set_menu_bar_lines_1 (f->root_window, nlines - olines);
174 adjust_glyphs (f);
178 Lisp_Object Vframe_list;
181 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
182 doc: /* Return non-nil if OBJECT is a frame.
183 Value is:
184 t for a termcap frame (a character-only terminal),
185 'x' for an Emacs frame that is really an X window,
186 'w32' for an Emacs frame that is a window on MS-Windows display,
187 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
188 'pc' for a direct-write MS-DOS frame.
189 See also `frame-live-p'. */)
190 (Lisp_Object object)
192 if (!FRAMEP (object))
193 return Qnil;
194 switch (XFRAME (object)->output_method)
196 case output_initial: /* The initial frame is like a termcap frame. */
197 case output_termcap:
198 return Qt;
199 case output_x_window:
200 return Qx;
201 case output_w32:
202 return Qw32;
203 case output_msdos_raw:
204 return Qpc;
205 case output_mac:
206 return Qmac;
207 case output_ns:
208 return Qns;
209 default:
210 abort ();
214 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
215 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
216 Value is nil if OBJECT is not a live frame. If object is a live
217 frame, the return value indicates what sort of terminal device it is
218 displayed on. See the documentation of `framep' for possible
219 return values. */)
220 (Lisp_Object object)
222 return ((FRAMEP (object)
223 && FRAME_LIVE_P (XFRAME (object)))
224 ? Fframep (object)
225 : Qnil);
228 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
229 doc: /* The name of the window system that FRAME is displaying through.
230 The value is a symbol:
231 nil for a termcap frame (a character-only terminal),
232 'x' for an Emacs frame that is really an X window,
233 'w32' for an Emacs frame that is a window on MS-Windows display,
234 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
235 'pc' for a direct-write MS-DOS frame.
237 FRAME defaults to the currently selected frame.
239 Use of this function as a predicate is deprecated. Instead,
240 use `display-graphic-p' or any of the other `display-*-p'
241 predicates which report frame's specific UI-related capabilities. */)
242 (Lisp_Object frame)
244 Lisp_Object type;
245 if (NILP (frame))
246 frame = selected_frame;
248 type = Fframep (frame);
250 if (NILP (type))
251 wrong_type_argument (Qframep, frame);
253 if (EQ (type, Qt))
254 return Qnil;
255 else
256 return type;
259 struct frame *
260 make_frame (int mini_p)
262 Lisp_Object frame;
263 register struct frame *f;
264 register Lisp_Object root_window;
265 register Lisp_Object mini_window;
267 f = allocate_frame ();
268 XSETFRAME (frame, f);
270 f->desired_matrix = 0;
271 f->current_matrix = 0;
272 f->desired_pool = 0;
273 f->current_pool = 0;
274 f->glyphs_initialized_p = 0;
275 f->decode_mode_spec_buffer = 0;
276 f->visible = 0;
277 f->async_visible = 0;
278 f->output_data.nothing = 0;
279 f->iconified = 0;
280 f->async_iconified = 0;
281 f->wants_modeline = 1;
282 f->auto_raise = 0;
283 f->auto_lower = 0;
284 f->no_split = 0;
285 f->garbaged = 1;
286 f->has_minibuffer = mini_p;
287 f->focus_frame = Qnil;
288 f->explicit_name = 0;
289 f->can_have_scroll_bars = 0;
290 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
291 f->param_alist = Qnil;
292 f->scroll_bars = Qnil;
293 f->condemned_scroll_bars = Qnil;
294 f->face_alist = Qnil;
295 f->face_cache = NULL;
296 f->menu_bar_items = Qnil;
297 f->menu_bar_vector = Qnil;
298 f->menu_bar_items_used = 0;
299 f->buffer_predicate = Qnil;
300 f->buffer_list = Qnil;
301 f->buried_buffer_list = Qnil;
302 f->namebuf = 0;
303 f->title = Qnil;
304 f->menu_bar_window = Qnil;
305 f->tool_bar_window = Qnil;
306 f->tool_bar_items = Qnil;
307 f->tool_bar_position = Qtop;
308 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
309 f->n_tool_bar_items = 0;
310 f->left_fringe_width = f->right_fringe_width = 0;
311 f->fringe_cols = 0;
312 f->menu_bar_lines = 0;
313 f->tool_bar_lines = 0;
314 f->scroll_bar_actual_width = 0;
315 f->border_width = 0;
316 f->internal_border_width = 0;
317 f->column_width = 1; /* !FRAME_WINDOW_P value */
318 f->line_height = 1; /* !FRAME_WINDOW_P value */
319 f->x_pixels_diff = f->y_pixels_diff = 0;
320 #ifdef HAVE_WINDOW_SYSTEM
321 f->want_fullscreen = FULLSCREEN_NONE;
322 #endif
323 f->size_hint_flags = 0;
324 f->win_gravity = 0;
325 f->font_driver_list = NULL;
326 f->font_data_list = NULL;
328 root_window = make_window ();
329 if (mini_p)
331 mini_window = make_window ();
332 XWINDOW (root_window)->next = mini_window;
333 XWINDOW (mini_window)->prev = root_window;
334 XWINDOW (mini_window)->mini_p = Qt;
335 XWINDOW (mini_window)->frame = frame;
336 f->minibuffer_window = mini_window;
338 else
340 mini_window = Qnil;
341 XWINDOW (root_window)->next = Qnil;
342 f->minibuffer_window = Qnil;
345 XWINDOW (root_window)->frame = frame;
347 /* 10 is arbitrary,
348 just so that there is "something there."
349 Correct size will be set up later with change_frame_size. */
351 SET_FRAME_COLS (f, 10);
352 FRAME_LINES (f) = 10;
354 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
355 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
357 if (mini_p)
359 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
360 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
361 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
364 /* Choose a buffer for the frame's root window. */
366 Lisp_Object buf;
368 XWINDOW (root_window)->buffer = Qt;
369 buf = Fcurrent_buffer ();
370 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
371 a space), try to find another one. */
372 if (SREF (Fbuffer_name (buf), 0) == ' ')
373 buf = other_buffer_safely (buf);
375 /* Use set_window_buffer, not Fset_window_buffer, and don't let
376 hooks be run by it. The reason is that the whole frame/window
377 arrangement is not yet fully initialized at this point. Windows
378 don't have the right size, glyph matrices aren't initialized
379 etc. Running Lisp functions at this point surely ends in a
380 SEGV. */
381 set_window_buffer (root_window, buf, 0, 0);
382 f->buffer_list = Fcons (buf, Qnil);
385 if (mini_p)
387 XWINDOW (mini_window)->buffer = Qt;
388 set_window_buffer (mini_window,
389 (NILP (Vminibuffer_list)
390 ? get_minibuffer (0)
391 : Fcar (Vminibuffer_list)),
392 0, 0);
395 f->root_window = root_window;
396 f->selected_window = root_window;
397 /* Make sure this window seems more recently used than
398 a newly-created, never-selected window. */
399 ++window_select_count;
400 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
402 f->default_face_done_p = 0;
404 return f;
407 #ifdef HAVE_WINDOW_SYSTEM
408 /* Make a frame using a separate minibuffer window on another frame.
409 MINI_WINDOW is the minibuffer window to use. nil means use the
410 default (the global minibuffer). */
412 struct frame *
413 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
415 register struct frame *f;
416 struct gcpro gcpro1;
418 if (!NILP (mini_window))
419 CHECK_LIVE_WINDOW (mini_window);
421 if (!NILP (mini_window)
422 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
423 error ("Frame and minibuffer must be on the same terminal");
425 /* Make a frame containing just a root window. */
426 f = make_frame (0);
428 if (NILP (mini_window))
430 /* Use default-minibuffer-frame if possible. */
431 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
432 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
434 Lisp_Object frame_dummy;
436 XSETFRAME (frame_dummy, f);
437 GCPRO1 (frame_dummy);
438 /* If there's no minibuffer frame to use, create one. */
439 KVAR (kb, Vdefault_minibuffer_frame) =
440 call1 (intern ("make-initial-minibuffer-frame"), display);
441 UNGCPRO;
444 mini_window = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
447 f->minibuffer_window = mini_window;
449 /* Make the chosen minibuffer window display the proper minibuffer,
450 unless it is already showing a minibuffer. */
451 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
452 Fset_window_buffer (mini_window,
453 (NILP (Vminibuffer_list)
454 ? get_minibuffer (0)
455 : Fcar (Vminibuffer_list)), Qnil);
456 return f;
459 /* Make a frame containing only a minibuffer window. */
461 struct frame *
462 make_minibuffer_frame (void)
464 /* First make a frame containing just a root window, no minibuffer. */
466 register struct frame *f = make_frame (0);
467 register Lisp_Object mini_window;
468 register Lisp_Object frame;
470 XSETFRAME (frame, f);
472 f->auto_raise = 0;
473 f->auto_lower = 0;
474 f->no_split = 1;
475 f->wants_modeline = 0;
476 f->has_minibuffer = 1;
478 /* Now label the root window as also being the minibuffer.
479 Avoid infinite looping on the window chain by marking next pointer
480 as nil. */
482 mini_window = f->minibuffer_window = f->root_window;
483 XWINDOW (mini_window)->mini_p = Qt;
484 XWINDOW (mini_window)->next = Qnil;
485 XWINDOW (mini_window)->prev = Qnil;
486 XWINDOW (mini_window)->frame = frame;
488 /* Put the proper buffer in that window. */
490 Fset_window_buffer (mini_window,
491 (NILP (Vminibuffer_list)
492 ? get_minibuffer (0)
493 : Fcar (Vminibuffer_list)), Qnil);
494 return f;
496 #endif /* HAVE_WINDOW_SYSTEM */
498 /* Construct a frame that refers to a terminal. */
500 static printmax_t tty_frame_count;
502 struct frame *
503 make_initial_frame (void)
505 struct frame *f;
506 struct terminal *terminal;
507 Lisp_Object frame;
509 eassert (initial_kboard);
511 /* The first call must initialize Vframe_list. */
512 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
513 Vframe_list = Qnil;
515 terminal = init_initial_terminal ();
517 f = make_frame (1);
518 XSETFRAME (frame, f);
520 Vframe_list = Fcons (frame, Vframe_list);
522 tty_frame_count = 1;
523 f->name = make_pure_c_string ("F1");
525 f->visible = 1;
526 f->async_visible = 1;
528 f->output_method = terminal->type;
529 f->terminal = terminal;
530 f->terminal->reference_count++;
531 f->output_data.nothing = 0;
533 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
534 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
536 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
537 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
539 /* The default value of menu-bar-mode is t. */
540 set_menu_bar_lines (f, make_number (1), Qnil);
542 if (!noninteractive)
543 init_frame_faces (f);
545 return f;
549 static struct frame *
550 make_terminal_frame (struct terminal *terminal)
552 register struct frame *f;
553 Lisp_Object frame;
554 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
556 if (!terminal->name)
557 error ("Terminal is not live, can't create new frames on it");
559 f = make_frame (1);
561 XSETFRAME (frame, f);
562 Vframe_list = Fcons (frame, Vframe_list);
564 tty_frame_count++;
565 sprintf (name, "F%"pMd, tty_frame_count);
566 f->name = build_string (name);
568 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
569 f->async_visible = 1; /* Don't let visible be cleared later. */
570 f->terminal = terminal;
571 f->terminal->reference_count++;
572 #ifdef MSDOS
573 f->output_data.tty->display_info = &the_only_display_info;
574 if (!inhibit_window_system
575 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
576 || XFRAME (selected_frame)->output_method == output_msdos_raw))
577 f->output_method = output_msdos_raw;
578 else
579 f->output_method = output_termcap;
580 #else /* not MSDOS */
581 f->output_method = output_termcap;
582 create_tty_output (f);
583 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
584 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
585 #endif /* not MSDOS */
587 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
588 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
589 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
591 /* Set the top frame to the newly created frame. */
592 if (FRAMEP (FRAME_TTY (f)->top_frame)
593 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
594 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
596 FRAME_TTY (f)->top_frame = frame;
598 if (!noninteractive)
599 init_frame_faces (f);
601 return f;
604 /* Get a suitable value for frame parameter PARAMETER for a newly
605 created frame, based on (1) the user-supplied frame parameter
606 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
608 static Lisp_Object
609 get_future_frame_param (Lisp_Object parameter,
610 Lisp_Object supplied_parms,
611 char *current_value)
613 Lisp_Object result;
615 result = Fassq (parameter, supplied_parms);
616 if (NILP (result))
617 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
618 if (NILP (result) && current_value != NULL)
619 result = build_string (current_value);
620 if (!NILP (result) && !STRINGP (result))
621 result = XCDR (result);
622 if (NILP (result) || !STRINGP (result))
623 result = Qnil;
625 return result;
628 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
629 1, 1, 0,
630 doc: /* Create an additional terminal frame, possibly on another terminal.
631 This function takes one argument, an alist specifying frame parameters.
633 You can create multiple frames on a single text-only terminal, but
634 only one of them (the selected terminal frame) is actually displayed.
636 In practice, generally you don't need to specify any parameters,
637 except when you want to create a new frame on another terminal.
638 In that case, the `tty' parameter specifies the device file to open,
639 and the `tty-type' parameter specifies the terminal type. Example:
641 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
643 Note that changing the size of one terminal frame automatically
644 affects all frames on the same terminal device. */)
645 (Lisp_Object parms)
647 struct frame *f;
648 struct terminal *t = NULL;
649 Lisp_Object frame, tem;
650 struct frame *sf = SELECTED_FRAME ();
652 #ifdef MSDOS
653 if (sf->output_method != output_msdos_raw
654 && sf->output_method != output_termcap)
655 abort ();
656 #else /* not MSDOS */
658 #ifdef WINDOWSNT /* This should work now! */
659 if (sf->output_method != output_termcap)
660 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
661 #endif
662 #endif /* not MSDOS */
665 Lisp_Object terminal;
667 terminal = Fassq (Qterminal, parms);
668 if (!NILP (terminal))
670 terminal = XCDR (terminal);
671 t = get_terminal (terminal, 1);
673 #ifdef MSDOS
674 if (t && t != the_only_display_info.terminal)
675 /* msdos.c assumes a single tty_display_info object. */
676 error ("Multiple terminals are not supported on this platform");
677 if (!t)
678 t = the_only_display_info.terminal;
679 #endif
682 if (!t)
684 char *name = 0, *type = 0;
685 Lisp_Object tty, tty_type;
687 tty = get_future_frame_param
688 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
689 ? FRAME_TTY (XFRAME (selected_frame))->name
690 : NULL));
691 if (!NILP (tty))
693 name = (char *) alloca (SBYTES (tty) + 1);
694 strncpy (name, SSDATA (tty), SBYTES (tty));
695 name[SBYTES (tty)] = 0;
698 tty_type = get_future_frame_param
699 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
700 ? FRAME_TTY (XFRAME (selected_frame))->type
701 : NULL));
702 if (!NILP (tty_type))
704 type = (char *) alloca (SBYTES (tty_type) + 1);
705 strncpy (type, SSDATA (tty_type), SBYTES (tty_type));
706 type[SBYTES (tty_type)] = 0;
709 t = init_tty (name, type, 0); /* Errors are not fatal. */
712 f = make_terminal_frame (t);
715 int width, height;
716 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
717 change_frame_size (f, height, width, 0, 0, 0);
720 adjust_glyphs (f);
721 calculate_costs (f);
722 XSETFRAME (frame, f);
723 Fmodify_frame_parameters (frame, parms);
724 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
725 build_string (t->display_info.tty->type)),
726 Qnil));
727 if (t->display_info.tty->name != NULL)
728 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
729 build_string (t->display_info.tty->name)),
730 Qnil));
731 else
732 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
734 /* Make the frame face alist be frame-specific, so that each
735 frame could change its face definitions independently. */
736 f->face_alist = Fcopy_alist (sf->face_alist);
737 /* Simple Fcopy_alist isn't enough, because we need the contents of
738 the vectors which are the CDRs of associations in face_alist to
739 be copied as well. */
740 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
741 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
742 return frame;
746 /* Perform the switch to frame FRAME.
748 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
749 FRAME1 as frame.
751 If TRACK is non-zero and the frame that currently has the focus
752 redirects its focus to the selected frame, redirect that focused
753 frame's focus to FRAME instead.
755 FOR_DELETION non-zero means that the selected frame is being
756 deleted, which includes the possibility that the frame's terminal
757 is dead.
759 The value of NORECORD is passed as argument to Fselect_window. */
761 Lisp_Object
762 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
764 struct frame *sf = SELECTED_FRAME ();
766 /* If FRAME is a switch-frame event, extract the frame we should
767 switch to. */
768 if (CONSP (frame)
769 && EQ (XCAR (frame), Qswitch_frame)
770 && CONSP (XCDR (frame)))
771 frame = XCAR (XCDR (frame));
773 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
774 a switch-frame event to arrive after a frame is no longer live,
775 especially when deleting the initial frame during startup. */
776 CHECK_FRAME (frame);
777 if (! FRAME_LIVE_P (XFRAME (frame)))
778 return Qnil;
780 if (sf == XFRAME (frame))
781 return frame;
783 /* This is too greedy; it causes inappropriate focus redirection
784 that's hard to get rid of. */
785 #if 0
786 /* If a frame's focus has been redirected toward the currently
787 selected frame, we should change the redirection to point to the
788 newly selected frame. This means that if the focus is redirected
789 from a minibufferless frame to a surrogate minibuffer frame, we
790 can use `other-window' to switch between all the frames using
791 that minibuffer frame, and the focus redirection will follow us
792 around. */
793 if (track)
795 Lisp_Object tail;
797 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
799 Lisp_Object focus;
801 if (!FRAMEP (XCAR (tail)))
802 abort ();
804 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
806 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
807 Fredirect_frame_focus (XCAR (tail), frame);
810 #else /* ! 0 */
811 /* Instead, apply it only to the frame we're pointing to. */
812 #ifdef HAVE_WINDOW_SYSTEM
813 if (track && FRAME_WINDOW_P (XFRAME (frame)))
815 Lisp_Object focus, xfocus;
817 xfocus = x_get_focus_frame (XFRAME (frame));
818 if (FRAMEP (xfocus))
820 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
821 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
822 Fredirect_frame_focus (xfocus, frame);
825 #endif /* HAVE_X_WINDOWS */
826 #endif /* ! 0 */
828 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
829 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
831 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
833 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
834 /* Mark previously displayed frame as now obscured. */
835 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
836 XFRAME (frame)->async_visible = 1;
837 FRAME_TTY (XFRAME (frame))->top_frame = frame;
840 selected_frame = frame;
841 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
842 last_nonminibuf_frame = XFRAME (selected_frame);
844 Fselect_window (XFRAME (frame)->selected_window, norecord);
846 /* We want to make sure that the next event generates a frame-switch
847 event to the appropriate frame. This seems kludgy to me, but
848 before you take it out, make sure that evaluating something like
849 (select-window (frame-root-window (new-frame))) doesn't end up
850 with your typing being interpreted in the new frame instead of
851 the one you're actually typing in. */
852 internal_last_event_frame = Qnil;
854 return frame;
857 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
858 doc: /* Select FRAME.
859 Subsequent editing commands apply to its selected window.
860 Optional argument NORECORD means to neither change the order of
861 recently selected windows nor the buffer list.
863 The selection of FRAME lasts until the next time the user does
864 something to select a different frame, or until the next time
865 this function is called. If you are using a window system, the
866 previously selected frame may be restored as the selected frame
867 when returning to the command loop, because it still may have
868 the window system's input focus. On a text-only terminal, the
869 next redisplay will display FRAME.
871 This function returns FRAME, or nil if FRAME has been deleted. */)
872 (Lisp_Object frame, Lisp_Object norecord)
874 return do_switch_frame (frame, 1, 0, norecord);
878 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
879 doc: /* Handle a switch-frame event EVENT.
880 Switch-frame events are usually bound to this function.
881 A switch-frame event tells Emacs that the window manager has requested
882 that the user's events be directed to the frame mentioned in the event.
883 This function selects the selected window of the frame of EVENT.
885 If EVENT is frame object, handle it as if it were a switch-frame event
886 to that frame. */)
887 (Lisp_Object event)
889 /* Preserve prefix arg that the command loop just cleared. */
890 KVAR (current_kboard, Vprefix_arg) = Vcurrent_prefix_arg;
891 Frun_hooks (1, &Qmouse_leave_buffer_hook);
892 return do_switch_frame (event, 0, 0, Qnil);
895 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
896 doc: /* Return the frame that is now selected. */)
897 (void)
899 return selected_frame;
902 DEFUN ("frame-list", Fframe_list, Sframe_list,
903 0, 0, 0,
904 doc: /* Return a list of all live frames. */)
905 (void)
907 Lisp_Object frames;
908 frames = Fcopy_sequence (Vframe_list);
909 #ifdef HAVE_WINDOW_SYSTEM
910 if (FRAMEP (tip_frame))
911 frames = Fdelq (tip_frame, frames);
912 #endif
913 return frames;
916 /* Return the next frame in the frame list after FRAME.
917 If MINIBUF is nil, exclude minibuffer-only frames.
918 If MINIBUF is a window, include only its own frame
919 and any frame now using that window as the minibuffer.
920 If MINIBUF is `visible', include all visible frames.
921 If MINIBUF is 0, include all visible and iconified frames.
922 Otherwise, include all frames. */
924 static Lisp_Object
925 next_frame (Lisp_Object frame, Lisp_Object minibuf)
927 Lisp_Object tail;
928 int passed = 0;
930 /* There must always be at least one frame in Vframe_list. */
931 if (! CONSP (Vframe_list))
932 abort ();
934 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
935 forever. Forestall that. */
936 CHECK_LIVE_FRAME (frame);
938 while (1)
939 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
941 Lisp_Object f;
943 f = XCAR (tail);
945 if (passed
946 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
947 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
948 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
949 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
951 /* Decide whether this frame is eligible to be returned. */
953 /* If we've looped all the way around without finding any
954 eligible frames, return the original frame. */
955 if (EQ (f, frame))
956 return f;
958 /* Let minibuf decide if this frame is acceptable. */
959 if (NILP (minibuf))
961 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
962 return f;
964 else if (EQ (minibuf, Qvisible))
966 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
967 if (FRAME_VISIBLE_P (XFRAME (f)))
968 return f;
970 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
972 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
973 if (FRAME_VISIBLE_P (XFRAME (f))
974 || FRAME_ICONIFIED_P (XFRAME (f)))
975 return f;
977 else if (WINDOWP (minibuf))
979 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
980 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
981 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
982 FRAME_FOCUS_FRAME (XFRAME (f))))
983 return f;
985 else
986 return f;
989 if (EQ (frame, f))
990 passed++;
994 /* Return the previous frame in the frame list before FRAME.
995 If MINIBUF is nil, exclude minibuffer-only frames.
996 If MINIBUF is a window, include only its own frame
997 and any frame now using that window as the minibuffer.
998 If MINIBUF is `visible', include all visible frames.
999 If MINIBUF is 0, include all visible and iconified frames.
1000 Otherwise, include all frames. */
1002 static Lisp_Object
1003 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1005 Lisp_Object tail;
1006 Lisp_Object prev;
1008 /* There must always be at least one frame in Vframe_list. */
1009 if (! CONSP (Vframe_list))
1010 abort ();
1012 prev = Qnil;
1013 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1015 Lisp_Object f;
1017 f = XCAR (tail);
1018 if (!FRAMEP (f))
1019 abort ();
1021 if (EQ (frame, f) && !NILP (prev))
1022 return prev;
1024 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1025 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1026 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1027 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1029 /* Decide whether this frame is eligible to be returned,
1030 according to minibuf. */
1031 if (NILP (minibuf))
1033 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1034 prev = f;
1036 else if (WINDOWP (minibuf))
1038 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1039 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1040 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1041 FRAME_FOCUS_FRAME (XFRAME (f))))
1042 prev = f;
1044 else if (EQ (minibuf, Qvisible))
1046 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1047 if (FRAME_VISIBLE_P (XFRAME (f)))
1048 prev = f;
1050 else if (XFASTINT (minibuf) == 0)
1052 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1053 if (FRAME_VISIBLE_P (XFRAME (f))
1054 || FRAME_ICONIFIED_P (XFRAME (f)))
1055 prev = f;
1057 else
1058 prev = f;
1062 /* We've scanned the entire list. */
1063 if (NILP (prev))
1064 /* We went through the whole frame list without finding a single
1065 acceptable frame. Return the original frame. */
1066 return frame;
1067 else
1068 /* There were no acceptable frames in the list before FRAME; otherwise,
1069 we would have returned directly from the loop. Since PREV is the last
1070 acceptable frame in the list, return it. */
1071 return prev;
1075 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1076 doc: /* Return the next frame in the frame list after FRAME.
1077 It considers only frames on the same terminal as FRAME.
1078 By default, skip minibuffer-only frames.
1079 If omitted, FRAME defaults to the selected frame.
1080 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1081 If MINIFRAME is a window, include only its own frame
1082 and any frame now using that window as the minibuffer.
1083 If MINIFRAME is `visible', include all visible frames.
1084 If MINIFRAME is 0, include all visible and iconified frames.
1085 Otherwise, include all frames. */)
1086 (Lisp_Object frame, Lisp_Object miniframe)
1088 if (NILP (frame))
1089 frame = selected_frame;
1091 CHECK_LIVE_FRAME (frame);
1092 return next_frame (frame, miniframe);
1095 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1096 doc: /* Return the previous frame in the frame list before FRAME.
1097 It considers only frames on the same terminal as FRAME.
1098 By default, skip minibuffer-only frames.
1099 If omitted, FRAME defaults to the selected frame.
1100 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1101 If MINIFRAME is a window, include only its own frame
1102 and any frame now using that window as the minibuffer.
1103 If MINIFRAME is `visible', include all visible frames.
1104 If MINIFRAME is 0, include all visible and iconified frames.
1105 Otherwise, include all frames. */)
1106 (Lisp_Object frame, Lisp_Object miniframe)
1108 if (NILP (frame))
1109 frame = selected_frame;
1110 CHECK_LIVE_FRAME (frame);
1111 return prev_frame (frame, miniframe);
1114 /* Return 1 if it is ok to delete frame F;
1115 0 if all frames aside from F are invisible.
1116 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1118 static int
1119 other_visible_frames (FRAME_PTR f)
1121 /* We know the selected frame is visible,
1122 so if F is some other frame, it can't be the sole visible one. */
1123 if (f == SELECTED_FRAME ())
1125 Lisp_Object frames;
1126 int count = 0;
1128 for (frames = Vframe_list;
1129 CONSP (frames);
1130 frames = XCDR (frames))
1132 Lisp_Object this;
1134 this = XCAR (frames);
1135 /* Verify that the frame's window still exists
1136 and we can still talk to it. And note any recent change
1137 in visibility. */
1138 #ifdef HAVE_WINDOW_SYSTEM
1139 if (FRAME_WINDOW_P (XFRAME (this)))
1141 x_sync (XFRAME (this));
1142 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1144 #endif
1146 if (FRAME_VISIBLE_P (XFRAME (this))
1147 || FRAME_ICONIFIED_P (XFRAME (this))
1148 /* Allow deleting the terminal frame when at least
1149 one X frame exists! */
1150 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1151 count++;
1153 return count > 1;
1155 return 1;
1158 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1159 unconditionally. x_connection_closed and delete_terminal use
1160 this. Any other value of FORCE implements the semantics
1161 described for Fdelete_frame. */
1162 Lisp_Object
1163 delete_frame (Lisp_Object frame, Lisp_Object force)
1164 /* If we use `register' here, gcc-4.0.2 on amd64 using
1165 -DUSE_LISP_UNION_TYPE complains further down that we're getting the
1166 address of `force'. Go figure. */
1169 struct frame *f;
1170 struct frame *sf = SELECTED_FRAME ();
1171 struct kboard *kb;
1173 int minibuffer_selected, tooltip_frame;
1175 if (EQ (frame, Qnil))
1177 f = sf;
1178 XSETFRAME (frame, f);
1180 else
1182 CHECK_FRAME (frame);
1183 f = XFRAME (frame);
1186 if (! FRAME_LIVE_P (f))
1187 return Qnil;
1189 if (NILP (force) && !other_visible_frames (f))
1190 error ("Attempt to delete the sole visible or iconified frame");
1192 /* x_connection_closed must have set FORCE to `noelisp' in order
1193 to delete the last frame, if it is gone. */
1194 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1195 error ("Attempt to delete the only frame");
1197 /* Does this frame have a minibuffer, and is it the surrogate
1198 minibuffer for any other frame? */
1199 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1201 Lisp_Object frames;
1203 for (frames = Vframe_list;
1204 CONSP (frames);
1205 frames = XCDR (frames))
1207 Lisp_Object this;
1208 this = XCAR (frames);
1210 if (! EQ (this, frame)
1211 && EQ (frame,
1212 WINDOW_FRAME (XWINDOW
1213 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1215 /* If we MUST delete this frame, delete the other first.
1216 But do this only if FORCE equals `noelisp'. */
1217 if (EQ (force, Qnoelisp))
1218 delete_frame (this, Qnoelisp);
1219 else
1220 error ("Attempt to delete a surrogate minibuffer frame");
1225 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1227 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1228 frame is a tooltip. FORCE is set to `noelisp' when handling
1229 a disconnect from the terminal, so we don't dare call Lisp
1230 code. */
1231 if (NILP (Vrun_hooks) || tooltip_frame)
1233 else if (EQ (force, Qnoelisp))
1234 pending_funcalls
1235 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1236 pending_funcalls);
1237 else
1239 #ifdef HAVE_X_WINDOWS
1240 /* Also, save clipboard to the clipboard manager. */
1241 x_clipboard_manager_save_frame (frame);
1242 #endif
1244 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1247 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1248 if (! FRAME_LIVE_P (f))
1249 return Qnil;
1251 /* At this point, we are committed to deleting the frame.
1252 There is no more chance for errors to prevent it. */
1254 minibuffer_selected = EQ (minibuf_window, selected_window);
1256 /* Don't let the frame remain selected. */
1257 if (f == sf)
1259 Lisp_Object tail, frame1;
1261 /* Look for another visible frame on the same terminal. */
1262 frame1 = next_frame (frame, Qvisible);
1264 /* If there is none, find *some* other frame. */
1265 if (NILP (frame1) || EQ (frame1, frame))
1267 FOR_EACH_FRAME (tail, frame1)
1269 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1270 break;
1273 #ifdef NS_IMPL_COCOA
1274 else
1275 /* Under NS, there is no system mechanism for choosing a new
1276 window to get focus -- it is left to application code.
1277 So the portion of THIS application interfacing with NS
1278 needs to know about it. We call Fraise_frame, but the
1279 purpose is really to transfer focus. */
1280 Fraise_frame (frame1);
1281 #endif
1283 do_switch_frame (frame1, 0, 1, Qnil);
1284 sf = SELECTED_FRAME ();
1287 /* Don't allow minibuf_window to remain on a deleted frame. */
1288 if (EQ (f->minibuffer_window, minibuf_window))
1290 Fset_window_buffer (sf->minibuffer_window,
1291 XWINDOW (minibuf_window)->buffer, Qnil);
1292 minibuf_window = sf->minibuffer_window;
1294 /* If the dying minibuffer window was selected,
1295 select the new one. */
1296 if (minibuffer_selected)
1297 Fselect_window (minibuf_window, Qnil);
1300 /* Don't let echo_area_window to remain on a deleted frame. */
1301 if (EQ (f->minibuffer_window, echo_area_window))
1302 echo_area_window = sf->minibuffer_window;
1304 /* Clear any X selections for this frame. */
1305 #ifdef HAVE_X_WINDOWS
1306 if (FRAME_X_P (f))
1307 x_clear_frame_selections (f);
1308 #endif
1310 /* Free glyphs.
1311 This function must be called before the window tree of the
1312 frame is deleted because windows contain dynamically allocated
1313 memory. */
1314 free_glyphs (f);
1316 #ifdef HAVE_WINDOW_SYSTEM
1317 /* Give chance to each font driver to free a frame specific data. */
1318 font_update_drivers (f, Qnil);
1319 #endif
1321 /* Mark all the windows that used to be on FRAME as deleted, and then
1322 remove the reference to them. */
1323 delete_all_child_windows (f->root_window);
1324 f->root_window = Qnil;
1326 Vframe_list = Fdelq (frame, Vframe_list);
1327 FRAME_SET_VISIBLE (f, 0);
1329 /* Allow the vector of menu bar contents to be freed in the next
1330 garbage collection. The frame object itself may not be garbage
1331 collected until much later, because recent_keys and other data
1332 structures can still refer to it. */
1333 f->menu_bar_vector = Qnil;
1335 free_font_driver_list (f);
1336 xfree (f->namebuf);
1337 xfree (f->decode_mode_spec_buffer);
1338 xfree (FRAME_INSERT_COST (f));
1339 xfree (FRAME_DELETEN_COST (f));
1340 xfree (FRAME_INSERTN_COST (f));
1341 xfree (FRAME_DELETE_COST (f));
1342 xfree (FRAME_MESSAGE_BUF (f));
1344 /* Since some events are handled at the interrupt level, we may get
1345 an event for f at any time; if we zero out the frame's terminal
1346 now, then we may trip up the event-handling code. Instead, we'll
1347 promise that the terminal of the frame must be valid until we
1348 have called the window-system-dependent frame destruction
1349 routine. */
1351 if (FRAME_TERMINAL (f)->delete_frame_hook)
1352 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1355 struct terminal *terminal = FRAME_TERMINAL (f);
1356 f->output_data.nothing = 0;
1357 f->terminal = 0; /* Now the frame is dead. */
1359 /* If needed, delete the terminal that this frame was on.
1360 (This must be done after the frame is killed.) */
1361 terminal->reference_count--;
1362 #ifdef USE_GTK
1363 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1364 bug.
1365 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1366 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1367 terminal->reference_count = 1;
1368 #endif /* USE_GTK */
1369 if (terminal->reference_count == 0)
1371 Lisp_Object tmp;
1372 XSETTERMINAL (tmp, terminal);
1374 kb = NULL;
1375 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1377 else
1378 kb = terminal->kboard;
1381 /* If we've deleted the last_nonminibuf_frame, then try to find
1382 another one. */
1383 if (f == last_nonminibuf_frame)
1385 Lisp_Object frames;
1387 last_nonminibuf_frame = 0;
1389 for (frames = Vframe_list;
1390 CONSP (frames);
1391 frames = XCDR (frames))
1393 f = XFRAME (XCAR (frames));
1394 if (!FRAME_MINIBUF_ONLY_P (f))
1396 last_nonminibuf_frame = f;
1397 break;
1402 /* If there's no other frame on the same kboard, get out of
1403 single-kboard state if we're in it for this kboard. */
1404 if (kb != NULL)
1406 Lisp_Object frames;
1407 /* Some frame we found on the same kboard, or nil if there are none. */
1408 Lisp_Object frame_on_same_kboard;
1410 frame_on_same_kboard = Qnil;
1412 for (frames = Vframe_list;
1413 CONSP (frames);
1414 frames = XCDR (frames))
1416 Lisp_Object this;
1417 struct frame *f1;
1419 this = XCAR (frames);
1420 if (!FRAMEP (this))
1421 abort ();
1422 f1 = XFRAME (this);
1424 if (kb == FRAME_KBOARD (f1))
1425 frame_on_same_kboard = this;
1428 if (NILP (frame_on_same_kboard))
1429 not_single_kboard_state (kb);
1433 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1434 find another one. Prefer minibuffer-only frames, but also notice
1435 frames with other windows. */
1436 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1438 Lisp_Object frames;
1440 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1441 Lisp_Object frame_with_minibuf;
1442 /* Some frame we found on the same kboard, or nil if there are none. */
1443 Lisp_Object frame_on_same_kboard;
1445 frame_on_same_kboard = Qnil;
1446 frame_with_minibuf = Qnil;
1448 for (frames = Vframe_list;
1449 CONSP (frames);
1450 frames = XCDR (frames))
1452 Lisp_Object this;
1453 struct frame *f1;
1455 this = XCAR (frames);
1456 if (!FRAMEP (this))
1457 abort ();
1458 f1 = XFRAME (this);
1460 /* Consider only frames on the same kboard
1461 and only those with minibuffers. */
1462 if (kb == FRAME_KBOARD (f1)
1463 && FRAME_HAS_MINIBUF_P (f1))
1465 frame_with_minibuf = this;
1466 if (FRAME_MINIBUF_ONLY_P (f1))
1467 break;
1470 if (kb == FRAME_KBOARD (f1))
1471 frame_on_same_kboard = this;
1474 if (!NILP (frame_on_same_kboard))
1476 /* We know that there must be some frame with a minibuffer out
1477 there. If this were not true, all of the frames present
1478 would have to be minibufferless, which implies that at some
1479 point their minibuffer frames must have been deleted, but
1480 that is prohibited at the top; you can't delete surrogate
1481 minibuffer frames. */
1482 if (NILP (frame_with_minibuf))
1483 abort ();
1485 KVAR (kb, Vdefault_minibuffer_frame) = frame_with_minibuf;
1487 else
1488 /* No frames left on this kboard--say no minibuffer either. */
1489 KVAR (kb, Vdefault_minibuffer_frame) = Qnil;
1492 /* Cause frame titles to update--necessary if we now have just one frame. */
1493 if (!tooltip_frame)
1494 update_mode_lines = 1;
1496 return Qnil;
1499 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1500 doc: /* Delete FRAME, permanently eliminating it from use.
1501 FRAME defaults to the selected frame.
1503 A frame may not be deleted if its minibuffer is used by other frames.
1504 Normally, you may not delete a frame if all other frames are invisible,
1505 but if the second optional argument FORCE is non-nil, you may do so.
1507 This function runs `delete-frame-functions' before actually
1508 deleting the frame, unless the frame is a tooltip.
1509 The functions are run with one argument, the frame to be deleted. */)
1510 (Lisp_Object frame, Lisp_Object force)
1512 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1516 /* Return mouse position in character cell units. */
1518 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1519 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1520 The position is given in character cells, where (0, 0) is the
1521 upper-left corner of the frame, X is the horizontal offset, and Y is
1522 the vertical offset.
1523 If Emacs is running on a mouseless terminal or hasn't been programmed
1524 to read the mouse position, it returns the selected frame for FRAME
1525 and nil for X and Y.
1526 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1527 passing the normal return value to that function as an argument,
1528 and returns whatever that function returns. */)
1529 (void)
1531 FRAME_PTR f;
1532 Lisp_Object lispy_dummy;
1533 enum scroll_bar_part party_dummy;
1534 Lisp_Object x, y, retval;
1535 int col, row;
1536 Time long_dummy;
1537 struct gcpro gcpro1;
1539 f = SELECTED_FRAME ();
1540 x = y = Qnil;
1542 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1543 /* It's okay for the hook to refrain from storing anything. */
1544 if (FRAME_TERMINAL (f)->mouse_position_hook)
1545 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1546 &lispy_dummy, &party_dummy,
1547 &x, &y,
1548 &long_dummy);
1549 if (! NILP (x))
1551 col = XINT (x);
1552 row = XINT (y);
1553 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1554 XSETINT (x, col);
1555 XSETINT (y, row);
1557 #endif
1558 XSETFRAME (lispy_dummy, f);
1559 retval = Fcons (lispy_dummy, Fcons (x, y));
1560 GCPRO1 (retval);
1561 if (!NILP (Vmouse_position_function))
1562 retval = call1 (Vmouse_position_function, retval);
1563 RETURN_UNGCPRO (retval);
1566 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1567 Smouse_pixel_position, 0, 0, 0,
1568 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1569 The position is given in pixel units, where (0, 0) is the
1570 upper-left corner of the frame, X is the horizontal offset, and Y is
1571 the vertical offset.
1572 If Emacs is running on a mouseless terminal or hasn't been programmed
1573 to read the mouse position, it returns the selected frame for FRAME
1574 and nil for X and Y. */)
1575 (void)
1577 FRAME_PTR f;
1578 Lisp_Object lispy_dummy;
1579 enum scroll_bar_part party_dummy;
1580 Lisp_Object x, y;
1581 Time long_dummy;
1583 f = SELECTED_FRAME ();
1584 x = y = Qnil;
1586 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1587 /* It's okay for the hook to refrain from storing anything. */
1588 if (FRAME_TERMINAL (f)->mouse_position_hook)
1589 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1590 &lispy_dummy, &party_dummy,
1591 &x, &y,
1592 &long_dummy);
1593 #endif
1594 XSETFRAME (lispy_dummy, f);
1595 return Fcons (lispy_dummy, Fcons (x, y));
1598 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1599 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1600 Coordinates are relative to the frame, not a window,
1601 so the coordinates of the top left character in the frame
1602 may be nonzero due to left-hand scroll bars or the menu bar.
1604 The position is given in character cells, where (0, 0) is the
1605 upper-left corner of the frame, X is the horizontal offset, and Y is
1606 the vertical offset.
1608 This function is a no-op for an X frame that is not visible.
1609 If you have just created a frame, you must wait for it to become visible
1610 before calling this function on it, like this.
1611 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1612 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1614 CHECK_LIVE_FRAME (frame);
1615 CHECK_TYPE_RANGED_INTEGER (int, x);
1616 CHECK_TYPE_RANGED_INTEGER (int, y);
1618 /* I think this should be done with a hook. */
1619 #ifdef HAVE_WINDOW_SYSTEM
1620 if (FRAME_WINDOW_P (XFRAME (frame)))
1621 /* Warping the mouse will cause enternotify and focus events. */
1622 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1623 #else
1624 #if defined (MSDOS) && defined (HAVE_MOUSE)
1625 if (FRAME_MSDOS_P (XFRAME (frame)))
1627 Fselect_frame (frame, Qnil);
1628 mouse_moveto (XINT (x), XINT (y));
1630 #else
1631 #ifdef HAVE_GPM
1633 Fselect_frame (frame, Qnil);
1634 term_mouse_moveto (XINT (x), XINT (y));
1636 #endif
1637 #endif
1638 #endif
1640 return Qnil;
1643 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1644 Sset_mouse_pixel_position, 3, 3, 0,
1645 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1646 The position is given in pixels, where (0, 0) is the upper-left corner
1647 of the frame, X is the horizontal offset, and Y is the vertical offset.
1649 Note, this is a no-op for an X frame that is not visible.
1650 If you have just created a frame, you must wait for it to become visible
1651 before calling this function on it, like this.
1652 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1653 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1655 CHECK_LIVE_FRAME (frame);
1656 CHECK_TYPE_RANGED_INTEGER (int, x);
1657 CHECK_TYPE_RANGED_INTEGER (int, y);
1659 /* I think this should be done with a hook. */
1660 #ifdef HAVE_WINDOW_SYSTEM
1661 if (FRAME_WINDOW_P (XFRAME (frame)))
1662 /* Warping the mouse will cause enternotify and focus events. */
1663 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1664 #else
1665 #if defined (MSDOS) && defined (HAVE_MOUSE)
1666 if (FRAME_MSDOS_P (XFRAME (frame)))
1668 Fselect_frame (frame, Qnil);
1669 mouse_moveto (XINT (x), XINT (y));
1671 #else
1672 #ifdef HAVE_GPM
1674 Fselect_frame (frame, Qnil);
1675 term_mouse_moveto (XINT (x), XINT (y));
1677 #endif
1678 #endif
1679 #endif
1681 return Qnil;
1684 static void make_frame_visible_1 (Lisp_Object);
1686 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1687 0, 1, "",
1688 doc: /* Make the frame FRAME visible (assuming it is an X window).
1689 If omitted, FRAME defaults to the currently selected frame. */)
1690 (Lisp_Object frame)
1692 if (NILP (frame))
1693 frame = selected_frame;
1695 CHECK_LIVE_FRAME (frame);
1697 /* I think this should be done with a hook. */
1698 #ifdef HAVE_WINDOW_SYSTEM
1699 if (FRAME_WINDOW_P (XFRAME (frame)))
1701 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1702 x_make_frame_visible (XFRAME (frame));
1704 #endif
1706 make_frame_visible_1 (XFRAME (frame)->root_window);
1708 /* Make menu bar update for the Buffers and Frames menus. */
1709 windows_or_buffers_changed++;
1711 return frame;
1714 /* Update the display_time slot of the buffers shown in WINDOW
1715 and all its descendants. */
1717 static void
1718 make_frame_visible_1 (Lisp_Object window)
1720 struct window *w;
1722 for (;!NILP (window); window = w->next)
1724 w = XWINDOW (window);
1726 if (!NILP (w->buffer))
1727 BVAR (XBUFFER (w->buffer), display_time) = Fcurrent_time ();
1729 if (!NILP (w->vchild))
1730 make_frame_visible_1 (w->vchild);
1731 if (!NILP (w->hchild))
1732 make_frame_visible_1 (w->hchild);
1736 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1737 0, 2, "",
1738 doc: /* Make the frame FRAME invisible.
1739 If omitted, FRAME defaults to the currently selected frame.
1740 On graphical displays, invisible frames are not updated and are
1741 usually not displayed at all, even in a window system's \"taskbar\".
1743 Normally you may not make FRAME invisible if all other frames are invisible,
1744 but if the second optional argument FORCE is non-nil, you may do so.
1746 This function has no effect on text-only terminal frames. Such frames
1747 are always considered visible, whether or not they are currently being
1748 displayed in the terminal. */)
1749 (Lisp_Object frame, Lisp_Object force)
1751 if (NILP (frame))
1752 frame = selected_frame;
1754 CHECK_LIVE_FRAME (frame);
1756 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1757 error ("Attempt to make invisible the sole visible or iconified frame");
1759 #if 0 /* This isn't logically necessary, and it can do GC. */
1760 /* Don't let the frame remain selected. */
1761 if (EQ (frame, selected_frame))
1762 do_switch_frame (next_frame (frame, Qt), 0, 0, Qnil)
1763 #endif
1765 /* Don't allow minibuf_window to remain on a deleted frame. */
1766 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1768 struct frame *sf = XFRAME (selected_frame);
1769 Fset_window_buffer (sf->minibuffer_window,
1770 XWINDOW (minibuf_window)->buffer, Qnil);
1771 minibuf_window = sf->minibuffer_window;
1774 /* I think this should be done with a hook. */
1775 #ifdef HAVE_WINDOW_SYSTEM
1776 if (FRAME_WINDOW_P (XFRAME (frame)))
1777 x_make_frame_invisible (XFRAME (frame));
1778 #endif
1780 /* Make menu bar update for the Buffers and Frames menus. */
1781 windows_or_buffers_changed++;
1783 return Qnil;
1786 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1787 0, 1, "",
1788 doc: /* Make the frame FRAME into an icon.
1789 If omitted, FRAME defaults to the currently selected frame. */)
1790 (Lisp_Object frame)
1792 if (NILP (frame))
1793 frame = selected_frame;
1795 CHECK_LIVE_FRAME (frame);
1797 #if 0 /* This isn't logically necessary, and it can do GC. */
1798 /* Don't let the frame remain selected. */
1799 if (EQ (frame, selected_frame))
1800 Fhandle_switch_frame (next_frame (frame, Qt));
1801 #endif
1803 /* Don't allow minibuf_window to remain on a deleted frame. */
1804 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1806 struct frame *sf = XFRAME (selected_frame);
1807 Fset_window_buffer (sf->minibuffer_window,
1808 XWINDOW (minibuf_window)->buffer, Qnil);
1809 minibuf_window = sf->minibuffer_window;
1812 /* I think this should be done with a hook. */
1813 #ifdef HAVE_WINDOW_SYSTEM
1814 if (FRAME_WINDOW_P (XFRAME (frame)))
1815 x_iconify_frame (XFRAME (frame));
1816 #endif
1818 /* Make menu bar update for the Buffers and Frames menus. */
1819 windows_or_buffers_changed++;
1821 return Qnil;
1824 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1825 1, 1, 0,
1826 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1827 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1828 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1829 On graphical displays, invisible frames are not updated and are
1830 usually not displayed at all, even in a window system's \"taskbar\".
1832 If FRAME is a text-only terminal frame, this always returns t.
1833 Such frames are always considered visible, whether or not they are
1834 currently being displayed on the terminal. */)
1835 (Lisp_Object frame)
1837 CHECK_LIVE_FRAME (frame);
1839 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1841 if (FRAME_VISIBLE_P (XFRAME (frame)))
1842 return Qt;
1843 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1844 return Qicon;
1845 return Qnil;
1848 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1849 0, 0, 0,
1850 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1851 (void)
1853 Lisp_Object tail, frame;
1854 struct frame *f;
1855 Lisp_Object value;
1857 value = Qnil;
1858 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1860 frame = XCAR (tail);
1861 if (!FRAMEP (frame))
1862 continue;
1863 f = XFRAME (frame);
1864 if (FRAME_VISIBLE_P (f))
1865 value = Fcons (frame, value);
1867 return value;
1871 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1872 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1873 If FRAME is invisible or iconified, make it visible.
1874 If you don't specify a frame, the selected frame is used.
1875 If Emacs is displaying on an ordinary terminal or some other device which
1876 doesn't support multiple overlapping frames, this function selects FRAME. */)
1877 (Lisp_Object frame)
1879 struct frame *f;
1880 if (NILP (frame))
1881 frame = selected_frame;
1883 CHECK_LIVE_FRAME (frame);
1885 f = XFRAME (frame);
1887 if (FRAME_TERMCAP_P (f))
1888 /* On a text-only terminal select FRAME. */
1889 Fselect_frame (frame, Qnil);
1890 else
1891 /* Do like the documentation says. */
1892 Fmake_frame_visible (frame);
1894 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1895 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1897 return Qnil;
1900 /* Should we have a corresponding function called Flower_Power? */
1901 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1902 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1903 If you don't specify a frame, the selected frame is used.
1904 If Emacs is displaying on an ordinary terminal or some other device which
1905 doesn't support multiple overlapping frames, this function does nothing. */)
1906 (Lisp_Object frame)
1908 struct frame *f;
1910 if (NILP (frame))
1911 frame = selected_frame;
1913 CHECK_LIVE_FRAME (frame);
1915 f = XFRAME (frame);
1917 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1918 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1920 return Qnil;
1924 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1925 1, 2, 0,
1926 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1927 In other words, switch-frame events caused by events in FRAME will
1928 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1929 FOCUS-FRAME after reading an event typed at FRAME.
1931 If FOCUS-FRAME is omitted or nil, any existing redirection is
1932 canceled, and the frame again receives its own keystrokes.
1934 Focus redirection is useful for temporarily redirecting keystrokes to
1935 a surrogate minibuffer frame when a frame doesn't have its own
1936 minibuffer window.
1938 A frame's focus redirection can be changed by `select-frame'. If frame
1939 FOO is selected, and then a different frame BAR is selected, any
1940 frames redirecting their focus to FOO are shifted to redirect their
1941 focus to BAR. This allows focus redirection to work properly when the
1942 user switches from one frame to another using `select-window'.
1944 This means that a frame whose focus is redirected to itself is treated
1945 differently from a frame whose focus is redirected to nil; the former
1946 is affected by `select-frame', while the latter is not.
1948 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1949 (Lisp_Object frame, Lisp_Object focus_frame)
1951 struct frame *f;
1953 /* Note that we don't check for a live frame here. It's reasonable
1954 to redirect the focus of a frame you're about to delete, if you
1955 know what other frame should receive those keystrokes. */
1956 CHECK_FRAME (frame);
1958 if (! NILP (focus_frame))
1959 CHECK_LIVE_FRAME (focus_frame);
1961 f = XFRAME (frame);
1963 f->focus_frame = focus_frame;
1965 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1966 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1968 return Qnil;
1972 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1973 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1974 This returns nil if FRAME's focus is not redirected.
1975 See `redirect-frame-focus'. */)
1976 (Lisp_Object frame)
1978 CHECK_LIVE_FRAME (frame);
1980 return FRAME_FOCUS_FRAME (XFRAME (frame));
1985 /* Return the value of frame parameter PROP in frame FRAME. */
1987 #if !HAVE_NS
1988 static
1989 #endif
1990 Lisp_Object
1991 get_frame_param (register struct frame *frame, Lisp_Object prop)
1993 register Lisp_Object tem;
1995 tem = Fassq (prop, frame->param_alist);
1996 if (EQ (tem, Qnil))
1997 return tem;
1998 return Fcdr (tem);
2001 /* Return the buffer-predicate of the selected frame. */
2003 Lisp_Object
2004 frame_buffer_predicate (Lisp_Object frame)
2006 return XFRAME (frame)->buffer_predicate;
2009 /* Return the buffer-list of the selected frame. */
2011 static Lisp_Object
2012 frame_buffer_list (Lisp_Object frame)
2014 return XFRAME (frame)->buffer_list;
2017 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2019 void
2020 frames_discard_buffer (Lisp_Object buffer)
2022 Lisp_Object frame, tail;
2024 FOR_EACH_FRAME (tail, frame)
2026 XFRAME (frame)->buffer_list
2027 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2028 XFRAME (frame)->buried_buffer_list
2029 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2033 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2034 If the alist already has an element for PROP, we change it. */
2036 void
2037 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2039 register Lisp_Object tem;
2041 tem = Fassq (prop, *alistptr);
2042 if (EQ (tem, Qnil))
2043 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2044 else
2045 Fsetcdr (tem, val);
2048 static int
2049 frame_name_fnn_p (char *str, ptrdiff_t len)
2051 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2053 char *p = str + 2;
2054 while ('0' <= *p && *p <= '9')
2055 p++;
2056 if (p == str + len)
2057 return 1;
2059 return 0;
2062 /* Set the name of the terminal frame. Also used by MSDOS frames.
2063 Modeled after x_set_name which is used for WINDOW frames. */
2065 static void
2066 set_term_frame_name (struct frame *f, Lisp_Object name)
2068 f->explicit_name = ! NILP (name);
2070 /* If NAME is nil, set the name to F<num>. */
2071 if (NILP (name))
2073 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2075 /* Check for no change needed in this very common case
2076 before we do any consing. */
2077 if (frame_name_fnn_p (SSDATA (f->name),
2078 SBYTES (f->name)))
2079 return;
2081 tty_frame_count++;
2082 sprintf (namebuf, "F%"pMd, tty_frame_count);
2083 name = build_string (namebuf);
2085 else
2087 CHECK_STRING (name);
2089 /* Don't change the name if it's already NAME. */
2090 if (! NILP (Fstring_equal (name, f->name)))
2091 return;
2093 /* Don't allow the user to set the frame name to F<num>, so it
2094 doesn't clash with the names we generate for terminal frames. */
2095 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2096 error ("Frame names of the form F<num> are usurped by Emacs");
2099 f->name = name;
2100 update_mode_lines = 1;
2103 void
2104 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2106 register Lisp_Object old_alist_elt;
2108 /* The buffer-list parameters are stored in a special place and not
2109 in the alist. All buffers must be live. */
2110 if (EQ (prop, Qbuffer_list))
2112 Lisp_Object list = Qnil;
2113 for (; CONSP (val); val = XCDR (val))
2114 if (!NILP (Fbuffer_live_p (XCAR (val))))
2115 list = Fcons (XCAR (val), list);
2116 f->buffer_list = Fnreverse (list);
2117 return;
2119 if (EQ (prop, Qburied_buffer_list))
2121 Lisp_Object list = Qnil;
2122 for (; CONSP (val); val = XCDR (val))
2123 if (!NILP (Fbuffer_live_p (XCAR (val))))
2124 list = Fcons (XCAR (val), list);
2125 f->buried_buffer_list = Fnreverse (list);
2126 return;
2129 /* If PROP is a symbol which is supposed to have frame-local values,
2130 and it is set up based on this frame, switch to the global
2131 binding. That way, we can create or alter the frame-local binding
2132 without messing up the symbol's status. */
2133 if (SYMBOLP (prop))
2135 struct Lisp_Symbol *sym = XSYMBOL (prop);
2136 start:
2137 switch (sym->redirect)
2139 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2140 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2141 case SYMBOL_LOCALIZED:
2142 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2143 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2144 swap_in_global_binding (sym);
2145 break;
2147 default: abort ();
2151 /* The tty color needed to be set before the frame's parameter
2152 alist was updated with the new value. This is not true any more,
2153 but we still do this test early on. */
2154 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2155 && f == FRAME_TTY (f)->previous_frame)
2156 /* Force redisplay of this tty. */
2157 FRAME_TTY (f)->previous_frame = NULL;
2159 /* Update the frame parameter alist. */
2160 old_alist_elt = Fassq (prop, f->param_alist);
2161 if (EQ (old_alist_elt, Qnil))
2162 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2163 else
2164 Fsetcdr (old_alist_elt, val);
2166 /* Update some other special parameters in their special places
2167 in addition to the alist. */
2169 if (EQ (prop, Qbuffer_predicate))
2170 f->buffer_predicate = val;
2172 if (! FRAME_WINDOW_P (f))
2174 if (EQ (prop, Qmenu_bar_lines))
2175 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2176 else if (EQ (prop, Qname))
2177 set_term_frame_name (f, val);
2180 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2182 if (! MINI_WINDOW_P (XWINDOW (val)))
2183 error ("Surrogate minibuffer windows must be minibuffer windows");
2185 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2186 && !EQ (val, f->minibuffer_window))
2187 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2189 /* Install the chosen minibuffer window, with proper buffer. */
2190 f->minibuffer_window = val;
2194 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2195 doc: /* Return the parameters-alist of frame FRAME.
2196 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2197 The meaningful PARMs depend on the kind of frame.
2198 If FRAME is omitted, return information on the currently selected frame. */)
2199 (Lisp_Object frame)
2201 Lisp_Object alist;
2202 FRAME_PTR f;
2203 int height, width;
2204 struct gcpro gcpro1;
2206 if (NILP (frame))
2207 frame = selected_frame;
2209 CHECK_FRAME (frame);
2210 f = XFRAME (frame);
2212 if (!FRAME_LIVE_P (f))
2213 return Qnil;
2215 alist = Fcopy_alist (f->param_alist);
2216 GCPRO1 (alist);
2218 if (!FRAME_WINDOW_P (f))
2220 int fg = FRAME_FOREGROUND_PIXEL (f);
2221 int bg = FRAME_BACKGROUND_PIXEL (f);
2222 Lisp_Object elt;
2224 /* If the frame's parameter alist says the colors are
2225 unspecified and reversed, take the frame's background pixel
2226 for foreground and vice versa. */
2227 elt = Fassq (Qforeground_color, alist);
2228 if (CONSP (elt) && STRINGP (XCDR (elt)))
2230 if (strncmp (SSDATA (XCDR (elt)),
2231 unspecified_bg,
2232 SCHARS (XCDR (elt))) == 0)
2233 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2234 else if (strncmp (SSDATA (XCDR (elt)),
2235 unspecified_fg,
2236 SCHARS (XCDR (elt))) == 0)
2237 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2239 else
2240 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2241 elt = Fassq (Qbackground_color, alist);
2242 if (CONSP (elt) && STRINGP (XCDR (elt)))
2244 if (strncmp (SSDATA (XCDR (elt)),
2245 unspecified_fg,
2246 SCHARS (XCDR (elt))) == 0)
2247 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2248 else if (strncmp (SSDATA (XCDR (elt)),
2249 unspecified_bg,
2250 SCHARS (XCDR (elt))) == 0)
2251 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2253 else
2254 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2255 store_in_alist (&alist, intern ("font"),
2256 build_string (FRAME_MSDOS_P (f)
2257 ? "ms-dos"
2258 : FRAME_W32_P (f) ? "w32term"
2259 :"tty"));
2261 store_in_alist (&alist, Qname, f->name);
2262 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2263 store_in_alist (&alist, Qheight, make_number (height));
2264 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2265 store_in_alist (&alist, Qwidth, make_number (width));
2266 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2267 store_in_alist (&alist, Qminibuffer,
2268 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2269 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2270 : FRAME_MINIBUF_WINDOW (f)));
2271 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2272 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2273 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2275 /* I think this should be done with a hook. */
2276 #ifdef HAVE_WINDOW_SYSTEM
2277 if (FRAME_WINDOW_P (f))
2278 x_report_frame_params (f, &alist);
2279 else
2280 #endif
2282 /* This ought to be correct in f->param_alist for an X frame. */
2283 Lisp_Object lines;
2284 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2285 store_in_alist (&alist, Qmenu_bar_lines, lines);
2288 UNGCPRO;
2289 return alist;
2293 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2294 doc: /* Return FRAME's value for parameter PARAMETER.
2295 If FRAME is nil, describe the currently selected frame. */)
2296 (Lisp_Object frame, Lisp_Object parameter)
2298 struct frame *f;
2299 Lisp_Object value;
2301 if (NILP (frame))
2302 frame = selected_frame;
2303 else
2304 CHECK_FRAME (frame);
2305 CHECK_SYMBOL (parameter);
2307 f = XFRAME (frame);
2308 value = Qnil;
2310 if (FRAME_LIVE_P (f))
2312 /* Avoid consing in frequent cases. */
2313 if (EQ (parameter, Qname))
2314 value = f->name;
2315 #ifdef HAVE_X_WINDOWS
2316 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2317 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2318 #endif /* HAVE_X_WINDOWS */
2319 else if (EQ (parameter, Qbackground_color)
2320 || EQ (parameter, Qforeground_color))
2322 value = Fassq (parameter, f->param_alist);
2323 if (CONSP (value))
2325 value = XCDR (value);
2326 /* Fframe_parameters puts the actual fg/bg color names,
2327 even if f->param_alist says otherwise. This is
2328 important when param_alist's notion of colors is
2329 "unspecified". We need to do the same here. */
2330 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2332 const char *color_name;
2333 ptrdiff_t csz;
2335 if (EQ (parameter, Qbackground_color))
2337 color_name = SSDATA (value);
2338 csz = SCHARS (value);
2339 if (strncmp (color_name, unspecified_bg, csz) == 0)
2340 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2341 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2342 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2344 else if (EQ (parameter, Qforeground_color))
2346 color_name = SSDATA (value);
2347 csz = SCHARS (value);
2348 if (strncmp (color_name, unspecified_fg, csz) == 0)
2349 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2350 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2351 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2355 else
2356 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2358 else if (EQ (parameter, Qdisplay_type)
2359 || EQ (parameter, Qbackground_mode))
2360 value = Fcdr (Fassq (parameter, f->param_alist));
2361 else
2362 /* FIXME: Avoid this code path at all (as well as code duplication)
2363 by sharing more code with Fframe_parameters. */
2364 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2367 return value;
2371 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2372 Smodify_frame_parameters, 2, 2, 0,
2373 doc: /* Modify the parameters of frame FRAME according to ALIST.
2374 If FRAME is nil, it defaults to the selected frame.
2375 ALIST is an alist of parameters to change and their new values.
2376 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2377 The meaningful PARMs depend on the kind of frame.
2378 Undefined PARMs are ignored, but stored in the frame's parameter list
2379 so that `frame-parameters' will return them.
2381 The value of frame parameter FOO can also be accessed
2382 as a frame-local binding for the variable FOO, if you have
2383 enabled such bindings for that variable with `make-variable-frame-local'.
2384 Note that this functionality is obsolete as of Emacs 22.2, and its
2385 use is not recommended. Explicitly check for a frame-parameter instead. */)
2386 (Lisp_Object frame, Lisp_Object alist)
2388 FRAME_PTR f;
2389 register Lisp_Object tail, prop, val;
2391 if (EQ (frame, Qnil))
2392 frame = selected_frame;
2393 CHECK_LIVE_FRAME (frame);
2394 f = XFRAME (frame);
2396 /* I think this should be done with a hook. */
2397 #ifdef HAVE_WINDOW_SYSTEM
2398 if (FRAME_WINDOW_P (f))
2399 x_set_frame_parameters (f, alist);
2400 else
2401 #endif
2402 #ifdef MSDOS
2403 if (FRAME_MSDOS_P (f))
2404 IT_set_frame_parameters (f, alist);
2405 else
2406 #endif
2409 EMACS_INT length = XFASTINT (Flength (alist));
2410 ptrdiff_t i;
2411 Lisp_Object *parms;
2412 Lisp_Object *values;
2413 USE_SAFE_ALLOCA;
2414 SAFE_ALLOCA_LISP (parms, 2 * length);
2415 values = parms + length;
2417 /* Extract parm names and values into those vectors. */
2419 i = 0;
2420 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2422 Lisp_Object elt;
2424 elt = XCAR (tail);
2425 parms[i] = Fcar (elt);
2426 values[i] = Fcdr (elt);
2427 i++;
2430 /* Now process them in reverse of specified order. */
2431 while (--i >= 0)
2433 prop = parms[i];
2434 val = values[i];
2435 store_frame_param (f, prop, val);
2437 if (EQ (prop, Qforeground_color)
2438 || EQ (prop, Qbackground_color))
2439 update_face_from_frame_parameter (f, prop, val);
2442 SAFE_FREE ();
2444 return Qnil;
2447 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2448 0, 1, 0,
2449 doc: /* Height in pixels of a line in the font in frame FRAME.
2450 If FRAME is omitted, the selected frame is used.
2451 For a terminal frame, the value is always 1. */)
2452 (Lisp_Object frame)
2454 struct frame *f;
2456 if (NILP (frame))
2457 frame = selected_frame;
2458 CHECK_FRAME (frame);
2459 f = XFRAME (frame);
2461 #ifdef HAVE_WINDOW_SYSTEM
2462 if (FRAME_WINDOW_P (f))
2463 return make_number (x_char_height (f));
2464 else
2465 #endif
2466 return make_number (1);
2470 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2471 0, 1, 0,
2472 doc: /* Width in pixels of characters in the font in frame FRAME.
2473 If FRAME is omitted, the selected frame is used.
2474 On a graphical screen, the width is the standard width of the default font.
2475 For a terminal screen, the value is always 1. */)
2476 (Lisp_Object frame)
2478 struct frame *f;
2480 if (NILP (frame))
2481 frame = selected_frame;
2482 CHECK_FRAME (frame);
2483 f = XFRAME (frame);
2485 #ifdef HAVE_WINDOW_SYSTEM
2486 if (FRAME_WINDOW_P (f))
2487 return make_number (x_char_width (f));
2488 else
2489 #endif
2490 return make_number (1);
2493 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2494 Sframe_pixel_height, 0, 1, 0,
2495 doc: /* Return a FRAME's height in pixels.
2496 If FRAME is omitted, the selected frame is used. The exact value
2497 of the result depends on the window-system and toolkit in use:
2499 In the Gtk+ version of Emacs, it includes only any window (including
2500 the minibuffer or echo area), mode line, and header line. It does not
2501 include the tool bar or menu bar.
2503 With the Motif or Lucid toolkits, it also includes the tool bar (but
2504 not the menu bar).
2506 In a graphical version with no toolkit, it includes both the tool bar
2507 and menu bar.
2509 For a text-only terminal, it includes the menu bar. In this case, the
2510 result is really in characters rather than pixels (i.e., is identical
2511 to `frame-height'). */)
2512 (Lisp_Object frame)
2514 struct frame *f;
2516 if (NILP (frame))
2517 frame = selected_frame;
2518 CHECK_FRAME (frame);
2519 f = XFRAME (frame);
2521 #ifdef HAVE_WINDOW_SYSTEM
2522 if (FRAME_WINDOW_P (f))
2523 return make_number (x_pixel_height (f));
2524 else
2525 #endif
2526 return make_number (FRAME_LINES (f));
2529 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2530 Sframe_pixel_width, 0, 1, 0,
2531 doc: /* Return FRAME's width in pixels.
2532 For a terminal frame, the result really gives the width in characters.
2533 If FRAME is omitted, the selected frame is used. */)
2534 (Lisp_Object frame)
2536 struct frame *f;
2538 if (NILP (frame))
2539 frame = selected_frame;
2540 CHECK_FRAME (frame);
2541 f = XFRAME (frame);
2543 #ifdef HAVE_WINDOW_SYSTEM
2544 if (FRAME_WINDOW_P (f))
2545 return make_number (x_pixel_width (f));
2546 else
2547 #endif
2548 return make_number (FRAME_COLS (f));
2551 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2552 Stool_bar_pixel_width, 0, 1, 0,
2553 doc: /* Return width in pixels of FRAME's tool bar.
2554 The result is greater than zero only when the tool bar is on the left
2555 or right side of FRAME. If FRAME is omitted, the selected frame is
2556 used. */)
2557 (Lisp_Object frame)
2559 struct frame *f;
2561 if (NILP (frame))
2562 frame = selected_frame;
2563 CHECK_FRAME (frame);
2564 f = XFRAME (frame);
2566 #ifdef FRAME_TOOLBAR_WIDTH
2567 if (FRAME_WINDOW_P (f))
2568 return make_number (FRAME_TOOLBAR_WIDTH (f));
2569 #endif
2570 return make_number (0);
2573 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2574 doc: /* Specify that the frame FRAME has LINES lines.
2575 Optional third arg non-nil means that redisplay should use LINES lines
2576 but that the idea of the actual height of the frame should not be changed. */)
2577 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2579 register struct frame *f;
2581 CHECK_TYPE_RANGED_INTEGER (int, lines);
2582 if (NILP (frame))
2583 frame = selected_frame;
2584 CHECK_LIVE_FRAME (frame);
2585 f = XFRAME (frame);
2587 /* I think this should be done with a hook. */
2588 #ifdef HAVE_WINDOW_SYSTEM
2589 if (FRAME_WINDOW_P (f))
2591 if (XINT (lines) != FRAME_LINES (f))
2592 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2593 do_pending_window_change (0);
2595 else
2596 #endif
2597 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2598 return Qnil;
2601 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2602 doc: /* Specify that the frame FRAME has COLS columns.
2603 Optional third arg non-nil means that redisplay should use COLS columns
2604 but that the idea of the actual width of the frame should not be changed. */)
2605 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2607 register struct frame *f;
2608 CHECK_TYPE_RANGED_INTEGER (int, cols);
2609 if (NILP (frame))
2610 frame = selected_frame;
2611 CHECK_LIVE_FRAME (frame);
2612 f = XFRAME (frame);
2614 /* I think this should be done with a hook. */
2615 #ifdef HAVE_WINDOW_SYSTEM
2616 if (FRAME_WINDOW_P (f))
2618 if (XINT (cols) != FRAME_COLS (f))
2619 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2620 do_pending_window_change (0);
2622 else
2623 #endif
2624 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2625 return Qnil;
2628 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2629 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2630 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2632 register struct frame *f;
2634 CHECK_LIVE_FRAME (frame);
2635 CHECK_TYPE_RANGED_INTEGER (int, cols);
2636 CHECK_TYPE_RANGED_INTEGER (int, rows);
2637 f = XFRAME (frame);
2639 /* I think this should be done with a hook. */
2640 #ifdef HAVE_WINDOW_SYSTEM
2641 if (FRAME_WINDOW_P (f))
2643 if (XINT (rows) != FRAME_LINES (f)
2644 || XINT (cols) != FRAME_COLS (f)
2645 || f->new_text_lines || f->new_text_cols)
2646 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2647 do_pending_window_change (0);
2649 else
2650 #endif
2651 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2653 return Qnil;
2656 DEFUN ("set-frame-position", Fset_frame_position,
2657 Sset_frame_position, 3, 3, 0,
2658 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2659 This is actually the position of the upper left corner of the frame.
2660 Negative values for XOFFSET or YOFFSET are interpreted relative to
2661 the rightmost or bottommost possible position (that stays within the screen). */)
2662 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2664 register struct frame *f;
2666 CHECK_LIVE_FRAME (frame);
2667 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2668 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2669 f = XFRAME (frame);
2671 /* I think this should be done with a hook. */
2672 #ifdef HAVE_WINDOW_SYSTEM
2673 if (FRAME_WINDOW_P (f))
2674 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2675 #endif
2677 return Qt;
2681 /***********************************************************************
2682 Frame Parameters
2683 ***********************************************************************/
2685 /* Connect the frame-parameter names for X frames
2686 to the ways of passing the parameter values to the window system.
2688 The name of a parameter, as a Lisp symbol,
2689 has an `x-frame-parameter' property which is an integer in Lisp
2690 that is an index in this table. */
2692 struct frame_parm_table {
2693 const char *name;
2694 Lisp_Object *variable;
2697 static const struct frame_parm_table frame_parms[] =
2699 {"auto-raise", &Qauto_raise},
2700 {"auto-lower", &Qauto_lower},
2701 {"background-color", 0},
2702 {"border-color", &Qborder_color},
2703 {"border-width", &Qborder_width},
2704 {"cursor-color", &Qcursor_color},
2705 {"cursor-type", &Qcursor_type},
2706 {"font", 0},
2707 {"foreground-color", 0},
2708 {"icon-name", &Qicon_name},
2709 {"icon-type", &Qicon_type},
2710 {"internal-border-width", &Qinternal_border_width},
2711 {"menu-bar-lines", &Qmenu_bar_lines},
2712 {"mouse-color", &Qmouse_color},
2713 {"name", &Qname},
2714 {"scroll-bar-width", &Qscroll_bar_width},
2715 {"title", &Qtitle},
2716 {"unsplittable", &Qunsplittable},
2717 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2718 {"visibility", &Qvisibility},
2719 {"tool-bar-lines", &Qtool_bar_lines},
2720 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2721 {"scroll-bar-background", &Qscroll_bar_background},
2722 {"screen-gamma", &Qscreen_gamma},
2723 {"line-spacing", &Qline_spacing},
2724 {"left-fringe", &Qleft_fringe},
2725 {"right-fringe", &Qright_fringe},
2726 {"wait-for-wm", &Qwait_for_wm},
2727 {"fullscreen", &Qfullscreen},
2728 {"font-backend", &Qfont_backend},
2729 {"alpha", &Qalpha},
2730 {"sticky", &Qsticky},
2731 {"tool-bar-position", &Qtool_bar_position},
2734 #ifdef WINDOWSNT
2736 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2737 wanted positions of the WM window (not Emacs window).
2738 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2739 window (FRAME_X_WINDOW).
2742 void
2743 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2745 int newwidth = FRAME_COLS (f);
2746 int newheight = FRAME_LINES (f);
2747 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2749 *top_pos = f->top_pos;
2750 *left_pos = f->left_pos;
2752 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2754 int ph;
2756 ph = x_display_pixel_height (dpyinfo);
2757 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2758 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2759 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2760 *top_pos = 0;
2763 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2765 int pw;
2767 pw = x_display_pixel_width (dpyinfo);
2768 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2769 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2770 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2771 *left_pos = 0;
2774 *width = newwidth;
2775 *height = newheight;
2778 #endif /* WINDOWSNT */
2780 #ifdef HAVE_WINDOW_SYSTEM
2782 /* Change the parameters of frame F as specified by ALIST.
2783 If a parameter is not specially recognized, do nothing special;
2784 otherwise call the `x_set_...' function for that parameter.
2785 Except for certain geometry properties, always call store_frame_param
2786 to store the new value in the parameter alist. */
2788 void
2789 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2791 Lisp_Object tail;
2793 /* If both of these parameters are present, it's more efficient to
2794 set them both at once. So we wait until we've looked at the
2795 entire list before we set them. */
2796 int width, height;
2798 /* Same here. */
2799 Lisp_Object left, top;
2801 /* Same with these. */
2802 Lisp_Object icon_left, icon_top;
2804 /* Record in these vectors all the parms specified. */
2805 Lisp_Object *parms;
2806 Lisp_Object *values;
2807 ptrdiff_t i, p;
2808 int left_no_change = 0, top_no_change = 0;
2809 int icon_left_no_change = 0, icon_top_no_change = 0;
2810 int size_changed = 0;
2811 struct gcpro gcpro1, gcpro2;
2813 i = 0;
2814 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2815 i++;
2817 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2818 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2820 /* Extract parm names and values into those vectors. */
2822 i = 0;
2823 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2825 Lisp_Object elt;
2827 elt = XCAR (tail);
2828 parms[i] = Fcar (elt);
2829 values[i] = Fcdr (elt);
2830 i++;
2832 /* TAIL and ALIST are not used again below here. */
2833 alist = tail = Qnil;
2835 GCPRO2 (*parms, *values);
2836 gcpro1.nvars = i;
2837 gcpro2.nvars = i;
2839 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2840 because their values appear in VALUES and strings are not valid. */
2841 top = left = Qunbound;
2842 icon_left = icon_top = Qunbound;
2844 /* Provide default values for HEIGHT and WIDTH. */
2845 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2846 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2848 /* Process foreground_color and background_color before anything else.
2849 They are independent of other properties, but other properties (e.g.,
2850 cursor_color) are dependent upon them. */
2851 /* Process default font as well, since fringe widths depends on it. */
2852 for (p = 0; p < i; p++)
2854 Lisp_Object prop, val;
2856 prop = parms[p];
2857 val = values[p];
2858 if (EQ (prop, Qforeground_color)
2859 || EQ (prop, Qbackground_color)
2860 || EQ (prop, Qfont))
2862 register Lisp_Object param_index, old_value;
2864 old_value = get_frame_param (f, prop);
2865 if (NILP (Fequal (val, old_value)))
2867 store_frame_param (f, prop, val);
2869 param_index = Fget (prop, Qx_frame_parameter);
2870 if (NATNUMP (param_index)
2871 && (XFASTINT (param_index)
2872 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2873 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2874 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2879 /* Now process them in reverse of specified order. */
2880 while (i-- != 0)
2882 Lisp_Object prop, val;
2884 prop = parms[i];
2885 val = values[i];
2887 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2889 size_changed = 1;
2890 width = XFASTINT (val);
2892 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2894 size_changed = 1;
2895 height = XFASTINT (val);
2897 else if (EQ (prop, Qtop))
2898 top = val;
2899 else if (EQ (prop, Qleft))
2900 left = val;
2901 else if (EQ (prop, Qicon_top))
2902 icon_top = val;
2903 else if (EQ (prop, Qicon_left))
2904 icon_left = val;
2905 else if (EQ (prop, Qforeground_color)
2906 || EQ (prop, Qbackground_color)
2907 || EQ (prop, Qfont))
2908 /* Processed above. */
2909 continue;
2910 else
2912 register Lisp_Object param_index, old_value;
2914 old_value = get_frame_param (f, prop);
2916 store_frame_param (f, prop, val);
2918 param_index = Fget (prop, Qx_frame_parameter);
2919 if (NATNUMP (param_index)
2920 && (XFASTINT (param_index)
2921 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2922 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2923 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2927 /* Don't die if just one of these was set. */
2928 if (! TYPE_RANGED_INTEGERP (int, left))
2930 left_no_change = 1;
2931 if (f->left_pos < 0)
2932 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2933 else
2934 XSETINT (left, f->left_pos);
2936 if (! TYPE_RANGED_INTEGERP (int, top))
2938 top_no_change = 1;
2939 if (f->top_pos < 0)
2940 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2941 else
2942 XSETINT (top, f->top_pos);
2945 /* If one of the icon positions was not set, preserve or default it. */
2946 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2948 icon_left_no_change = 1;
2949 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2950 if (NILP (icon_left))
2951 XSETINT (icon_left, 0);
2953 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2955 icon_top_no_change = 1;
2956 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2957 if (NILP (icon_top))
2958 XSETINT (icon_top, 0);
2961 /* Don't set these parameters unless they've been explicitly
2962 specified. The window might be mapped or resized while we're in
2963 this function, and we don't want to override that unless the lisp
2964 code has asked for it.
2966 Don't set these parameters unless they actually differ from the
2967 window's current parameters; the window may not actually exist
2968 yet. */
2970 Lisp_Object frame;
2972 check_frame_size (f, &height, &width);
2974 XSETFRAME (frame, f);
2976 if (size_changed
2977 && (width != FRAME_COLS (f)
2978 || height != FRAME_LINES (f)
2979 || f->new_text_lines || f->new_text_cols))
2980 Fset_frame_size (frame, make_number (width), make_number (height));
2982 if ((!NILP (left) || !NILP (top))
2983 && ! (left_no_change && top_no_change)
2984 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2985 && NUMBERP (top) && XINT (top) == f->top_pos))
2987 int leftpos = 0;
2988 int toppos = 0;
2990 /* Record the signs. */
2991 f->size_hint_flags &= ~ (XNegative | YNegative);
2992 if (EQ (left, Qminus))
2993 f->size_hint_flags |= XNegative;
2994 else if (TYPE_RANGED_INTEGERP (int, left))
2996 leftpos = XINT (left);
2997 if (leftpos < 0)
2998 f->size_hint_flags |= XNegative;
3000 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3001 && CONSP (XCDR (left))
3002 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
3004 leftpos = - XINT (XCAR (XCDR (left)));
3005 f->size_hint_flags |= XNegative;
3007 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3008 && CONSP (XCDR (left))
3009 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
3011 leftpos = XINT (XCAR (XCDR (left)));
3014 if (EQ (top, Qminus))
3015 f->size_hint_flags |= YNegative;
3016 else if (TYPE_RANGED_INTEGERP (int, top))
3018 toppos = XINT (top);
3019 if (toppos < 0)
3020 f->size_hint_flags |= YNegative;
3022 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3023 && CONSP (XCDR (top))
3024 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
3026 toppos = - XINT (XCAR (XCDR (top)));
3027 f->size_hint_flags |= YNegative;
3029 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3030 && CONSP (XCDR (top))
3031 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
3033 toppos = XINT (XCAR (XCDR (top)));
3037 /* Store the numeric value of the position. */
3038 f->top_pos = toppos;
3039 f->left_pos = leftpos;
3041 f->win_gravity = NorthWestGravity;
3043 /* Actually set that position, and convert to absolute. */
3044 x_set_offset (f, leftpos, toppos, -1);
3047 if ((!NILP (icon_left) || !NILP (icon_top))
3048 && ! (icon_left_no_change && icon_top_no_change))
3049 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3052 UNGCPRO;
3056 /* Insert a description of internally-recorded parameters of frame X
3057 into the parameter alist *ALISTPTR that is to be given to the user.
3058 Only parameters that are specific to the X window system
3059 and whose values are not correctly recorded in the frame's
3060 param_alist need to be considered here. */
3062 void
3063 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3065 char buf[16];
3066 Lisp_Object tem;
3067 unsigned long w;
3069 /* Represent negative positions (off the top or left screen edge)
3070 in a way that Fmodify_frame_parameters will understand correctly. */
3071 XSETINT (tem, f->left_pos);
3072 if (f->left_pos >= 0)
3073 store_in_alist (alistptr, Qleft, tem);
3074 else
3075 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3077 XSETINT (tem, f->top_pos);
3078 if (f->top_pos >= 0)
3079 store_in_alist (alistptr, Qtop, tem);
3080 else
3081 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3083 store_in_alist (alistptr, Qborder_width,
3084 make_number (f->border_width));
3085 store_in_alist (alistptr, Qinternal_border_width,
3086 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3087 store_in_alist (alistptr, Qleft_fringe,
3088 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3089 store_in_alist (alistptr, Qright_fringe,
3090 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3091 store_in_alist (alistptr, Qscroll_bar_width,
3092 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3093 ? make_number (0)
3094 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3095 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3096 /* nil means "use default width"
3097 for non-toolkit scroll bar.
3098 ruler-mode.el depends on this. */
3099 : Qnil));
3100 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3101 MS-Windows it returns a value whose type is HANDLE, which is
3102 actually a pointer. Explicit casting avoids compiler
3103 warnings. */
3104 w = (unsigned long) FRAME_X_WINDOW (f);
3105 sprintf (buf, "%lu", w);
3106 store_in_alist (alistptr, Qwindow_id,
3107 build_string (buf));
3108 #ifdef HAVE_X_WINDOWS
3109 #ifdef USE_X_TOOLKIT
3110 /* Tooltip frame may not have this widget. */
3111 if (FRAME_X_OUTPUT (f)->widget)
3112 #endif
3114 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3115 sprintf (buf, "%lu", w);
3117 store_in_alist (alistptr, Qouter_window_id,
3118 build_string (buf));
3119 #endif
3120 store_in_alist (alistptr, Qicon_name, f->icon_name);
3121 FRAME_SAMPLE_VISIBILITY (f);
3122 store_in_alist (alistptr, Qvisibility,
3123 (FRAME_VISIBLE_P (f) ? Qt
3124 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3125 store_in_alist (alistptr, Qdisplay,
3126 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3128 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3129 tem = Qnil;
3130 else
3131 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3132 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3133 store_in_alist (alistptr, Qparent_id, tem);
3134 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3138 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3139 the previous value of that parameter, NEW_VALUE is the new value. */
3141 void
3142 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3144 if (NILP (new_value))
3145 f->want_fullscreen = FULLSCREEN_NONE;
3146 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3147 f->want_fullscreen = FULLSCREEN_BOTH;
3148 else if (EQ (new_value, Qfullwidth))
3149 f->want_fullscreen = FULLSCREEN_WIDTH;
3150 else if (EQ (new_value, Qfullheight))
3151 f->want_fullscreen = FULLSCREEN_HEIGHT;
3152 else if (EQ (new_value, Qmaximized))
3153 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3155 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3156 FRAME_TERMINAL (f)->fullscreen_hook (f);
3160 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3161 the previous value of that parameter, NEW_VALUE is the new value. */
3163 void
3164 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3166 if (NILP (new_value))
3167 f->extra_line_spacing = 0;
3168 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3169 f->extra_line_spacing = XFASTINT (new_value);
3170 else
3171 signal_error ("Invalid line-spacing", new_value);
3172 if (FRAME_VISIBLE_P (f))
3173 redraw_frame (f);
3177 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3178 the previous value of that parameter, NEW_VALUE is the new value. */
3180 void
3181 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3183 Lisp_Object bgcolor;
3185 if (NILP (new_value))
3186 f->gamma = 0;
3187 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3188 /* The value 0.4545 is the normal viewing gamma. */
3189 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3190 else
3191 signal_error ("Invalid screen-gamma", new_value);
3193 /* Apply the new gamma value to the frame background. */
3194 bgcolor = Fassq (Qbackground_color, f->param_alist);
3195 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3197 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3198 if (NATNUMP (parm_index)
3199 && (XFASTINT (parm_index)
3200 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3201 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3202 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3203 (f, bgcolor, Qnil);
3206 Fclear_face_cache (Qnil);
3210 void
3211 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3213 Lisp_Object font_object, font_param = Qnil;
3214 int fontset = -1;
3216 /* Set the frame parameter back to the old value because we may
3217 fail to use ARG as the new parameter value. */
3218 store_frame_param (f, Qfont, oldval);
3220 /* ARG is a fontset name, a font name, a cons of fontset name and a
3221 font object, or a font object. In the last case, this function
3222 never fail. */
3223 if (STRINGP (arg))
3225 font_param = arg;
3226 fontset = fs_query_fontset (arg, 0);
3227 if (fontset < 0)
3229 font_object = font_open_by_name (f, SSDATA (arg));
3230 if (NILP (font_object))
3231 error ("Font `%s' is not defined", SSDATA (arg));
3232 arg = AREF (font_object, FONT_NAME_INDEX);
3234 else if (fontset > 0)
3236 Lisp_Object ascii_font = fontset_ascii (fontset);
3238 font_object = font_open_by_name (f, SSDATA (ascii_font));
3239 if (NILP (font_object))
3240 error ("Font `%s' is not defined", SDATA (arg));
3241 arg = AREF (font_object, FONT_NAME_INDEX);
3243 else
3244 error ("The default fontset can't be used for a frame font");
3246 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3248 /* This is the case that the ASCII font of F's fontset XCAR
3249 (arg) is changed to the font XCDR (arg) by
3250 `set-fontset-font'. */
3251 fontset = fs_query_fontset (XCAR (arg), 0);
3252 if (fontset < 0)
3253 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3254 font_object = XCDR (arg);
3255 arg = AREF (font_object, FONT_NAME_INDEX);
3256 font_param = Ffont_get (font_object, QCname);
3258 else if (FONT_OBJECT_P (arg))
3260 font_object = arg;
3261 font_param = Ffont_get (font_object, QCname);
3262 /* This is to store the XLFD font name in the frame parameter for
3263 backward compatibility. We should store the font-object
3264 itself in the future. */
3265 arg = AREF (font_object, FONT_NAME_INDEX);
3266 fontset = FRAME_FONTSET (f);
3267 /* Check if we can use the current fontset. If not, set FONTSET
3268 to -1 to generate a new fontset from FONT-OBJECT. */
3269 if (fontset >= 0)
3271 Lisp_Object ascii_font = fontset_ascii (fontset);
3272 Lisp_Object spec = font_spec_from_name (ascii_font);
3274 if (! font_match_p (spec, font_object))
3275 fontset = -1;
3278 else
3279 signal_error ("Invalid font", arg);
3281 if (! NILP (Fequal (font_object, oldval)))
3282 return;
3284 x_new_font (f, font_object, fontset);
3285 store_frame_param (f, Qfont, arg);
3286 #ifdef HAVE_X_WINDOWS
3287 store_frame_param (f, Qfont_param, font_param);
3288 #endif
3289 /* Recalculate toolbar height. */
3290 f->n_tool_bar_rows = 0;
3291 /* Ensure we redraw it. */
3292 clear_current_matrices (f);
3294 recompute_basic_faces (f);
3296 do_pending_window_change (0);
3298 /* We used to call face-set-after-frame-default here, but it leads to
3299 recursive calls (since that function can set the `default' face's
3300 font which in turns changes the frame's `font' parameter).
3301 Also I don't know what this call is meant to do, but it seems the
3302 wrong way to do it anyway (it does a lot more work than what seems
3303 reasonable in response to a change to `font'). */
3307 void
3308 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3310 if (! NILP (new_value)
3311 && !CONSP (new_value))
3313 char *p0, *p1;
3315 CHECK_STRING (new_value);
3316 p0 = p1 = SSDATA (new_value);
3317 new_value = Qnil;
3318 while (*p0)
3320 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3321 if (p0 < p1)
3322 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3323 new_value);
3324 if (*p1)
3326 int c;
3328 while ((c = *++p1) && isspace (c));
3330 p0 = p1;
3332 new_value = Fnreverse (new_value);
3335 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3336 return;
3338 if (FRAME_FONT (f))
3339 free_all_realized_faces (Qnil);
3341 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3342 if (NILP (new_value))
3344 if (NILP (old_value))
3345 error ("No font backend available");
3346 font_update_drivers (f, old_value);
3347 error ("None of specified font backends are available");
3349 store_frame_param (f, Qfont_backend, new_value);
3351 if (FRAME_FONT (f))
3353 Lisp_Object frame;
3355 XSETFRAME (frame, f);
3356 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3357 ++face_change_count;
3358 ++windows_or_buffers_changed;
3363 void
3364 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3366 compute_fringe_widths (f, 1);
3367 #ifdef HAVE_X_WINDOWS
3368 /* Must adjust this so window managers report correct number of columns. */
3369 if (FRAME_X_WINDOW (f) != 0)
3370 x_wm_set_size_hint (f, 0, 0);
3371 #endif
3374 void
3375 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3377 CHECK_TYPE_RANGED_INTEGER (int, arg);
3379 if (XINT (arg) == f->border_width)
3380 return;
3382 if (FRAME_X_WINDOW (f) != 0)
3383 error ("Cannot change the border width of a frame");
3385 f->border_width = XINT (arg);
3388 void
3389 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3391 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3393 CHECK_TYPE_RANGED_INTEGER (int, arg);
3394 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3395 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3396 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3398 #ifdef USE_X_TOOLKIT
3399 if (FRAME_X_OUTPUT (f)->edit_widget)
3400 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3401 #endif
3403 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3404 return;
3406 if (FRAME_X_WINDOW (f) != 0)
3408 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3409 SET_FRAME_GARBAGED (f);
3410 do_pending_window_change (0);
3412 else
3413 SET_FRAME_GARBAGED (f);
3416 void
3417 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3419 Lisp_Object frame;
3420 XSETFRAME (frame, f);
3422 if (NILP (value))
3423 Fmake_frame_invisible (frame, Qt);
3424 else if (EQ (value, Qicon))
3425 Ficonify_frame (frame);
3426 else
3427 Fmake_frame_visible (frame);
3430 void
3431 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3433 f->auto_raise = !EQ (Qnil, arg);
3436 void
3437 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3439 f->auto_lower = !EQ (Qnil, arg);
3442 void
3443 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3445 f->no_split = !NILP (arg);
3448 void
3449 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3451 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3452 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3453 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3454 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3456 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3457 = (NILP (arg)
3458 ? vertical_scroll_bar_none
3459 : EQ (Qleft, arg)
3460 ? vertical_scroll_bar_left
3461 : EQ (Qright, arg)
3462 ? vertical_scroll_bar_right
3463 : EQ (Qleft, Vdefault_frame_scroll_bars)
3464 ? vertical_scroll_bar_left
3465 : EQ (Qright, Vdefault_frame_scroll_bars)
3466 ? vertical_scroll_bar_right
3467 : vertical_scroll_bar_none);
3469 /* We set this parameter before creating the X window for the
3470 frame, so we can get the geometry right from the start.
3471 However, if the window hasn't been created yet, we shouldn't
3472 call x_set_window_size. */
3473 if (FRAME_X_WINDOW (f))
3474 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3475 do_pending_window_change (0);
3479 void
3480 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3482 int wid = FRAME_COLUMN_WIDTH (f);
3484 if (NILP (arg))
3486 x_set_scroll_bar_default_width (f);
3488 if (FRAME_X_WINDOW (f))
3489 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3490 do_pending_window_change (0);
3492 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3493 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3495 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3496 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3498 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3499 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3500 if (FRAME_X_WINDOW (f))
3501 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3502 do_pending_window_change (0);
3505 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3506 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3507 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3512 /* Return non-nil if frame F wants a bitmap icon. */
3514 Lisp_Object
3515 x_icon_type (FRAME_PTR f)
3517 Lisp_Object tem;
3519 tem = assq_no_quit (Qicon_type, f->param_alist);
3520 if (CONSP (tem))
3521 return XCDR (tem);
3522 else
3523 return Qnil;
3526 void
3527 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3529 double alpha = 1.0;
3530 double newval[2];
3531 int i;
3532 Lisp_Object item;
3534 for (i = 0; i < 2; i++)
3536 newval[i] = 1.0;
3537 if (CONSP (arg))
3539 item = CAR (arg);
3540 arg = CDR (arg);
3542 else
3543 item = arg;
3545 if (NILP (item))
3546 alpha = - 1.0;
3547 else if (FLOATP (item))
3549 alpha = XFLOAT_DATA (item);
3550 if (alpha < 0.0 || 1.0 < alpha)
3551 args_out_of_range (make_float (0.0), make_float (1.0));
3553 else if (INTEGERP (item))
3555 EMACS_INT ialpha = XINT (item);
3556 if (ialpha < 0 || 100 < ialpha)
3557 args_out_of_range (make_number (0), make_number (100));
3558 else
3559 alpha = ialpha / 100.0;
3561 else
3562 wrong_type_argument (Qnumberp, item);
3563 newval[i] = alpha;
3566 for (i = 0; i < 2; i++)
3567 f->alpha[i] = newval[i];
3569 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3570 BLOCK_INPUT;
3571 x_set_frame_alpha (f);
3572 UNBLOCK_INPUT;
3573 #endif
3575 return;
3579 /* Subroutines of creating an X frame. */
3581 /* Make sure that Vx_resource_name is set to a reasonable value.
3582 Fix it up, or set it to `emacs' if it is too hopeless. */
3584 void
3585 validate_x_resource_name (void)
3587 ptrdiff_t len = 0;
3588 /* Number of valid characters in the resource name. */
3589 ptrdiff_t good_count = 0;
3590 /* Number of invalid characters in the resource name. */
3591 ptrdiff_t bad_count = 0;
3592 Lisp_Object new;
3593 ptrdiff_t i;
3595 if (!STRINGP (Vx_resource_class))
3596 Vx_resource_class = build_string (EMACS_CLASS);
3598 if (STRINGP (Vx_resource_name))
3600 unsigned char *p = SDATA (Vx_resource_name);
3602 len = SBYTES (Vx_resource_name);
3604 /* Only letters, digits, - and _ are valid in resource names.
3605 Count the valid characters and count the invalid ones. */
3606 for (i = 0; i < len; i++)
3608 int c = p[i];
3609 if (! ((c >= 'a' && c <= 'z')
3610 || (c >= 'A' && c <= 'Z')
3611 || (c >= '0' && c <= '9')
3612 || c == '-' || c == '_'))
3613 bad_count++;
3614 else
3615 good_count++;
3618 else
3619 /* Not a string => completely invalid. */
3620 bad_count = 5, good_count = 0;
3622 /* If name is valid already, return. */
3623 if (bad_count == 0)
3624 return;
3626 /* If name is entirely invalid, or nearly so, or is so implausibly
3627 large that alloca might not work, use `emacs'. */
3628 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3630 Vx_resource_name = build_string ("emacs");
3631 return;
3634 /* Name is partly valid. Copy it and replace the invalid characters
3635 with underscores. */
3637 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3639 for (i = 0; i < len; i++)
3641 int c = SREF (new, i);
3642 if (! ((c >= 'a' && c <= 'z')
3643 || (c >= 'A' && c <= 'Z')
3644 || (c >= '0' && c <= '9')
3645 || c == '-' || c == '_'))
3646 SSET (new, i, '_');
3651 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3652 extern Display_Info *check_x_display_info (Lisp_Object);
3655 /* Get specified attribute from resource database RDB.
3656 See Fx_get_resource below for other parameters. */
3658 static Lisp_Object
3659 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3661 register char *value;
3662 char *name_key;
3663 char *class_key;
3665 CHECK_STRING (attribute);
3666 CHECK_STRING (class);
3668 if (!NILP (component))
3669 CHECK_STRING (component);
3670 if (!NILP (subclass))
3671 CHECK_STRING (subclass);
3672 if (NILP (component) != NILP (subclass))
3673 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3675 validate_x_resource_name ();
3677 /* Allocate space for the components, the dots which separate them,
3678 and the final '\0'. Make them big enough for the worst case. */
3679 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3680 + (STRINGP (component)
3681 ? SBYTES (component) : 0)
3682 + SBYTES (attribute)
3683 + 3);
3685 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3686 + SBYTES (class)
3687 + (STRINGP (subclass)
3688 ? SBYTES (subclass) : 0)
3689 + 3);
3691 /* Start with emacs.FRAMENAME for the name (the specific one)
3692 and with `Emacs' for the class key (the general one). */
3693 strcpy (name_key, SSDATA (Vx_resource_name));
3694 strcpy (class_key, SSDATA (Vx_resource_class));
3696 strcat (class_key, ".");
3697 strcat (class_key, SSDATA (class));
3699 if (!NILP (component))
3701 strcat (class_key, ".");
3702 strcat (class_key, SSDATA (subclass));
3704 strcat (name_key, ".");
3705 strcat (name_key, SSDATA (component));
3708 strcat (name_key, ".");
3709 strcat (name_key, SSDATA (attribute));
3711 value = x_get_string_resource (rdb, name_key, class_key);
3713 if (value != (char *) 0 && *value)
3714 return build_string (value);
3715 else
3716 return Qnil;
3720 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3721 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3722 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3723 class, where INSTANCE is the name under which Emacs was invoked, or
3724 the name specified by the `-name' or `-rn' command-line arguments.
3726 The optional arguments COMPONENT and SUBCLASS add to the key and the
3727 class, respectively. You must specify both of them or neither.
3728 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3729 and the class is `Emacs.CLASS.SUBCLASS'. */)
3730 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3732 #ifdef HAVE_X_WINDOWS
3733 check_x ();
3734 #endif
3736 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3737 attribute, class, component, subclass);
3740 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3742 Lisp_Object
3743 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3745 return xrdb_get_resource (dpyinfo->xrdb,
3746 attribute, class, component, subclass);
3749 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3750 /* Used when C code wants a resource value. */
3751 /* Called from oldXMenu/Create.c. */
3752 char *
3753 x_get_resource_string (const char *attribute, const char *class)
3755 char *name_key;
3756 char *class_key;
3757 char *result;
3758 struct frame *sf = SELECTED_FRAME ();
3759 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3760 USE_SAFE_ALLOCA;
3762 /* Allocate space for the components, the dots which separate them,
3763 and the final '\0'. */
3764 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3765 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3766 + strlen (class) + 2);
3768 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3769 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3771 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3772 name_key, class_key);
3773 SAFE_FREE ();
3774 return result;
3776 #endif
3778 /* Return the value of parameter PARAM.
3780 First search ALIST, then Vdefault_frame_alist, then the X defaults
3781 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3783 Convert the resource to the type specified by desired_type.
3785 If no default is specified, return Qunbound. If you call
3786 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3787 and don't let it get stored in any Lisp-visible variables! */
3789 Lisp_Object
3790 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3791 const char *attribute, const char *class, enum resource_types type)
3793 register Lisp_Object tem;
3795 tem = Fassq (param, alist);
3797 if (!NILP (tem))
3799 /* If we find this parm in ALIST, clear it out
3800 so that it won't be "left over" at the end. */
3801 Lisp_Object tail;
3802 XSETCAR (tem, Qnil);
3803 /* In case the parameter appears more than once in the alist,
3804 clear it out. */
3805 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3806 if (CONSP (XCAR (tail))
3807 && EQ (XCAR (XCAR (tail)), param))
3808 XSETCAR (XCAR (tail), Qnil);
3810 else
3811 tem = Fassq (param, Vdefault_frame_alist);
3813 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3814 look in the X resources. */
3815 if (EQ (tem, Qnil))
3817 if (attribute && dpyinfo)
3819 tem = display_x_get_resource (dpyinfo,
3820 build_string (attribute),
3821 build_string (class),
3822 Qnil, Qnil);
3824 if (NILP (tem))
3825 return Qunbound;
3827 switch (type)
3829 case RES_TYPE_NUMBER:
3830 return make_number (atoi (SSDATA (tem)));
3832 case RES_TYPE_BOOLEAN_NUMBER:
3833 if (!strcmp (SSDATA (tem), "on")
3834 || !strcmp (SSDATA (tem), "true"))
3835 return make_number (1);
3836 return make_number (atoi (SSDATA (tem)));
3837 break;
3839 case RES_TYPE_FLOAT:
3840 return make_float (atof (SSDATA (tem)));
3842 case RES_TYPE_BOOLEAN:
3843 tem = Fdowncase (tem);
3844 if (!strcmp (SSDATA (tem), "on")
3845 #ifdef HAVE_NS
3846 || !strcmp (SSDATA (tem), "yes")
3847 #endif
3848 || !strcmp (SSDATA (tem), "true"))
3849 return Qt;
3850 else
3851 return Qnil;
3853 case RES_TYPE_STRING:
3854 return tem;
3856 case RES_TYPE_SYMBOL:
3857 /* As a special case, we map the values `true' and `on'
3858 to Qt, and `false' and `off' to Qnil. */
3860 Lisp_Object lower;
3861 lower = Fdowncase (tem);
3862 if (!strcmp (SSDATA (lower), "on")
3863 #ifdef HAVE_NS
3864 || !strcmp (SSDATA (lower), "yes")
3865 #endif
3866 || !strcmp (SSDATA (lower), "true"))
3867 return Qt;
3868 else if (!strcmp (SSDATA (lower), "off")
3869 #ifdef HAVE_NS
3870 || !strcmp (SSDATA (lower), "no")
3871 #endif
3872 || !strcmp (SSDATA (lower), "false"))
3873 return Qnil;
3874 else
3875 return Fintern (tem, Qnil);
3878 default:
3879 abort ();
3882 else
3883 return Qunbound;
3885 return Fcdr (tem);
3888 static Lisp_Object
3889 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3890 const char *attribute, const char *class,
3891 enum resource_types type)
3893 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3894 alist, param, attribute, class, type);
3897 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3899 Lisp_Object
3900 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3901 Lisp_Object param,
3902 const char *attribute, const char *class,
3903 enum resource_types type)
3905 Lisp_Object value;
3907 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3908 attribute, class, type);
3909 if (! NILP (value) && ! EQ (value, Qunbound))
3910 store_frame_param (f, param, value);
3912 return value;
3916 /* Record in frame F the specified or default value according to ALIST
3917 of the parameter named PROP (a Lisp symbol).
3918 If no value is specified for PROP, look for an X default for XPROP
3919 on the frame named NAME.
3920 If that is not found either, use the value DEFLT. */
3922 Lisp_Object
3923 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3924 Lisp_Object deflt, const char *xprop, const char *xclass,
3925 enum resource_types type)
3927 Lisp_Object tem;
3929 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3930 if (EQ (tem, Qunbound))
3931 tem = deflt;
3932 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3933 return tem;
3939 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3940 make-docfile: the documentation string in ns-win.el was used for
3941 x-parse-geometry even in non-NS builds.
3943 With two definitions of x-parse-geometry in this file, various
3944 things still get confused (eg M-x apropos documentation), so that
3945 it is best if the two definitions just share the same doc-string.
3947 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3948 doc: /* Parse a display geometry string STRING.
3949 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3950 The properties returned may include `top', `left', `height', and `width'.
3951 For X, the value of `left' or `top' may be an integer,
3952 or a list (+ N) meaning N pixels relative to top/left corner,
3953 or a list (- N) meaning -N pixels relative to bottom/right corner.
3954 On Nextstep, this just calls `ns-parse-geometry'. */)
3955 (Lisp_Object string)
3957 #ifdef HAVE_NS
3958 call1 (Qns_parse_geometry, string);
3959 #else
3960 int geometry, x, y;
3961 unsigned int width, height;
3962 Lisp_Object result;
3964 CHECK_STRING (string);
3966 geometry = XParseGeometry (SSDATA (string),
3967 &x, &y, &width, &height);
3968 result = Qnil;
3969 if (geometry & XValue)
3971 Lisp_Object element;
3973 if (x >= 0 && (geometry & XNegative))
3974 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3975 else if (x < 0 && ! (geometry & XNegative))
3976 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3977 else
3978 element = Fcons (Qleft, make_number (x));
3979 result = Fcons (element, result);
3982 if (geometry & YValue)
3984 Lisp_Object element;
3986 if (y >= 0 && (geometry & YNegative))
3987 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3988 else if (y < 0 && ! (geometry & YNegative))
3989 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3990 else
3991 element = Fcons (Qtop, make_number (y));
3992 result = Fcons (element, result);
3995 if (geometry & WidthValue)
3996 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3997 if (geometry & HeightValue)
3998 result = Fcons (Fcons (Qheight, make_number (height)), result);
4000 return result;
4001 #endif /* HAVE_NS */
4005 /* Calculate the desired size and position of frame F.
4006 Return the flags saying which aspects were specified.
4008 Also set the win_gravity and size_hint_flags of F.
4010 Adjust height for toolbar if TOOLBAR_P is 1.
4012 This function does not make the coordinates positive. */
4014 #define DEFAULT_ROWS 35
4015 #define DEFAULT_COLS 80
4018 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
4020 register Lisp_Object tem0, tem1, tem2;
4021 long window_prompting = 0;
4022 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4024 /* Default values if we fall through.
4025 Actually, if that happens we should get
4026 window manager prompting. */
4027 SET_FRAME_COLS (f, DEFAULT_COLS);
4028 FRAME_LINES (f) = DEFAULT_ROWS;
4029 /* Window managers expect that if program-specified
4030 positions are not (0,0), they're intentional, not defaults. */
4031 f->top_pos = 0;
4032 f->left_pos = 0;
4034 /* Ensure that old new_text_cols and new_text_lines will not override the
4035 values set here. */
4036 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4037 f->new_text_cols = f->new_text_lines = 0;
4039 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4040 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4041 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4042 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4044 if (!EQ (tem0, Qunbound))
4046 CHECK_NUMBER (tem0);
4047 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4048 xsignal1 (Qargs_out_of_range, tem0);
4049 FRAME_LINES (f) = XINT (tem0);
4051 if (!EQ (tem1, Qunbound))
4053 CHECK_NUMBER (tem1);
4054 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4055 xsignal1 (Qargs_out_of_range, tem1);
4056 SET_FRAME_COLS (f, XINT (tem1));
4058 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4059 window_prompting |= USSize;
4060 else
4061 window_prompting |= PSize;
4064 f->scroll_bar_actual_width
4065 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4067 /* This used to be done _before_ calling x_figure_window_size, but
4068 since the height is reset here, this was really a no-op. I
4069 assume that moving it here does what Gerd intended (although he
4070 no longer can remember what that was... ++KFS, 2003-03-25. */
4072 /* Add the tool-bar height to the initial frame height so that the
4073 user gets a text display area of the size he specified with -g or
4074 via .Xdefaults. Later changes of the tool-bar height don't
4075 change the frame size. This is done so that users can create
4076 tall Emacs frames without having to guess how tall the tool-bar
4077 will get. */
4078 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4080 int margin, relief, bar_height;
4082 relief = (tool_bar_button_relief >= 0
4083 ? tool_bar_button_relief
4084 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4086 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4087 margin = XFASTINT (Vtool_bar_button_margin);
4088 else if (CONSP (Vtool_bar_button_margin)
4089 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4090 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4091 else
4092 margin = 0;
4094 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4095 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4098 compute_fringe_widths (f, 0);
4100 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4101 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4103 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4104 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4105 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4106 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4108 if (EQ (tem0, Qminus))
4110 f->top_pos = 0;
4111 window_prompting |= YNegative;
4113 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4114 && CONSP (XCDR (tem0))
4115 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4117 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4118 window_prompting |= YNegative;
4120 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4121 && CONSP (XCDR (tem0))
4122 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4124 f->top_pos = XINT (XCAR (XCDR (tem0)));
4126 else if (EQ (tem0, Qunbound))
4127 f->top_pos = 0;
4128 else
4130 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4131 f->top_pos = XINT (tem0);
4132 if (f->top_pos < 0)
4133 window_prompting |= YNegative;
4136 if (EQ (tem1, Qminus))
4138 f->left_pos = 0;
4139 window_prompting |= XNegative;
4141 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4142 && CONSP (XCDR (tem1))
4143 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4145 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4146 window_prompting |= XNegative;
4148 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4149 && CONSP (XCDR (tem1))
4150 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4152 f->left_pos = XINT (XCAR (XCDR (tem1)));
4154 else if (EQ (tem1, Qunbound))
4155 f->left_pos = 0;
4156 else
4158 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4159 f->left_pos = XINT (tem1);
4160 if (f->left_pos < 0)
4161 window_prompting |= XNegative;
4164 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4165 window_prompting |= USPosition;
4166 else
4167 window_prompting |= PPosition;
4170 if (window_prompting & XNegative)
4172 if (window_prompting & YNegative)
4173 f->win_gravity = SouthEastGravity;
4174 else
4175 f->win_gravity = NorthEastGravity;
4177 else
4179 if (window_prompting & YNegative)
4180 f->win_gravity = SouthWestGravity;
4181 else
4182 f->win_gravity = NorthWestGravity;
4185 f->size_hint_flags = window_prompting;
4187 return window_prompting;
4192 #endif /* HAVE_WINDOW_SYSTEM */
4194 void
4195 frame_make_pointer_invisible (void)
4197 if (! NILP (Vmake_pointer_invisible))
4199 struct frame *f;
4200 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4201 return;
4203 f = SELECTED_FRAME ();
4204 if (f && !f->pointer_invisible
4205 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4207 f->mouse_moved = 0;
4208 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4209 f->pointer_invisible = 1;
4214 void
4215 frame_make_pointer_visible (void)
4217 /* We don't check Vmake_pointer_invisible here in case the
4218 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4219 struct frame *f;
4221 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4222 return;
4224 f = SELECTED_FRAME ();
4225 if (f && f->pointer_invisible && f->mouse_moved
4226 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4228 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4229 f->pointer_invisible = 0;
4233 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4234 Sframe_pointer_visible_p, 0, 1, 0,
4235 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4236 Otherwise it returns nil. FRAME omitted or nil means the
4237 selected frame. This is useful when `make-pointer-invisible' is set. */)
4238 (Lisp_Object frame)
4240 if (NILP (frame))
4241 frame = selected_frame;
4243 CHECK_FRAME (frame);
4245 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4249 /***********************************************************************
4250 Initialization
4251 ***********************************************************************/
4253 void
4254 syms_of_frame (void)
4256 DEFSYM (Qframep, "framep");
4257 DEFSYM (Qframe_live_p, "frame-live-p");
4258 DEFSYM (Qexplicit_name, "explicit-name");
4259 DEFSYM (Qheight, "height");
4260 DEFSYM (Qicon, "icon");
4261 DEFSYM (Qminibuffer, "minibuffer");
4262 DEFSYM (Qmodeline, "modeline");
4263 DEFSYM (Qonly, "only");
4264 DEFSYM (Qwidth, "width");
4265 DEFSYM (Qgeometry, "geometry");
4266 DEFSYM (Qicon_left, "icon-left");
4267 DEFSYM (Qicon_top, "icon-top");
4268 DEFSYM (Qtooltip, "tooltip");
4269 DEFSYM (Qleft, "left");
4270 DEFSYM (Qright, "right");
4271 DEFSYM (Quser_position, "user-position");
4272 DEFSYM (Quser_size, "user-size");
4273 DEFSYM (Qwindow_id, "window-id");
4274 #ifdef HAVE_X_WINDOWS
4275 DEFSYM (Qouter_window_id, "outer-window-id");
4276 #endif
4277 DEFSYM (Qparent_id, "parent-id");
4278 DEFSYM (Qx, "x");
4279 DEFSYM (Qw32, "w32");
4280 DEFSYM (Qpc, "pc");
4281 DEFSYM (Qmac, "mac");
4282 DEFSYM (Qns, "ns");
4283 DEFSYM (Qvisible, "visible");
4284 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4285 DEFSYM (Qbuffer_list, "buffer-list");
4286 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4287 DEFSYM (Qdisplay_type, "display-type");
4288 DEFSYM (Qbackground_mode, "background-mode");
4289 DEFSYM (Qnoelisp, "noelisp");
4290 DEFSYM (Qtty_color_mode, "tty-color-mode");
4291 DEFSYM (Qtty, "tty");
4292 DEFSYM (Qtty_type, "tty-type");
4294 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4296 DEFSYM (Qfullwidth, "fullwidth");
4297 DEFSYM (Qfullheight, "fullheight");
4298 DEFSYM (Qfullboth, "fullboth");
4299 DEFSYM (Qmaximized, "maximized");
4300 DEFSYM (Qx_resource_name, "x-resource-name");
4301 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4303 DEFSYM (Qterminal, "terminal");
4304 DEFSYM (Qterminal_live_p, "terminal-live-p");
4306 #ifdef HAVE_NS
4307 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4308 #endif
4311 int i;
4313 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4315 Lisp_Object v = intern_c_string (frame_parms[i].name);
4316 if (frame_parms[i].variable)
4318 *frame_parms[i].variable = v;
4319 staticpro (frame_parms[i].variable);
4321 Fput (v, Qx_frame_parameter, make_number (i));
4325 #ifdef HAVE_WINDOW_SYSTEM
4326 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4327 doc: /* The name Emacs uses to look up X resources.
4328 `x-get-resource' uses this as the first component of the instance name
4329 when requesting resource values.
4330 Emacs initially sets `x-resource-name' to the name under which Emacs
4331 was invoked, or to the value specified with the `-name' or `-rn'
4332 switches, if present.
4334 It may be useful to bind this variable locally around a call
4335 to `x-get-resource'. See also the variable `x-resource-class'. */);
4336 Vx_resource_name = Qnil;
4338 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4339 doc: /* The class Emacs uses to look up X resources.
4340 `x-get-resource' uses this as the first component of the instance class
4341 when requesting resource values.
4343 Emacs initially sets `x-resource-class' to "Emacs".
4345 Setting this variable permanently is not a reasonable thing to do,
4346 but binding this variable locally around a call to `x-get-resource'
4347 is a reasonable practice. See also the variable `x-resource-name'. */);
4348 Vx_resource_class = build_string (EMACS_CLASS);
4350 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4351 doc: /* The lower limit of the frame opacity (alpha transparency).
4352 The value should range from 0 (invisible) to 100 (completely opaque).
4353 You can also use a floating number between 0.0 and 1.0.
4354 The default is 20. */);
4355 Vframe_alpha_lower_limit = make_number (20);
4356 #endif
4358 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4359 doc: /* Alist of default values for frame creation.
4360 These may be set in your init file, like this:
4361 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4362 These override values given in window system configuration data,
4363 including X Windows' defaults database.
4364 For values specific to the first Emacs frame, see `initial-frame-alist'.
4365 For window-system specific values, see `window-system-default-frame-alist'.
4366 For values specific to the separate minibuffer frame, see
4367 `minibuffer-frame-alist'.
4368 The `menu-bar-lines' element of the list controls whether new frames
4369 have menu bars; `menu-bar-mode' works by altering this element.
4370 Setting this variable does not affect existing frames, only new ones. */);
4371 Vdefault_frame_alist = Qnil;
4373 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4374 doc: /* Default position of scroll bars on this window-system. */);
4375 #ifdef HAVE_WINDOW_SYSTEM
4376 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4377 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4378 default. */
4379 Vdefault_frame_scroll_bars = Qright;
4380 #else
4381 Vdefault_frame_scroll_bars = Qleft;
4382 #endif
4383 #else
4384 Vdefault_frame_scroll_bars = Qnil;
4385 #endif
4387 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4388 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4390 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4391 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4392 `mouse-position' calls this function, passing its usual return value as
4393 argument, and returns whatever this function returns.
4394 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4395 which need to do mouse handling at the Lisp level. */);
4396 Vmouse_position_function = Qnil;
4398 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4399 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4400 If the value is an integer, highlighting is only shown after moving the
4401 mouse, while keyboard input turns off the highlight even when the mouse
4402 is over the clickable text. However, the mouse shape still indicates
4403 when the mouse is over clickable text. */);
4404 Vmouse_highlight = Qt;
4406 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4407 doc: /* If non-nil, make pointer invisible while typing.
4408 The pointer becomes visible again when the mouse is moved. */);
4409 Vmake_pointer_invisible = Qt;
4411 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4412 doc: /* Functions to be run before deleting a frame.
4413 The functions are run with one arg, the frame to be deleted.
4414 See `delete-frame'.
4416 Note that functions in this list may be called just before the frame is
4417 actually deleted, or some time later (or even both when an earlier function
4418 in `delete-frame-functions' (indirectly) calls `delete-frame'
4419 recursively). */);
4420 Vdelete_frame_functions = Qnil;
4421 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4423 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4424 doc: /* Non-nil if Menu-Bar mode is enabled.
4425 See the command `menu-bar-mode' for a description of this minor mode.
4426 Setting this variable directly does not take effect;
4427 either customize it (see the info node `Easy Customization')
4428 or call the function `menu-bar-mode'. */);
4429 Vmenu_bar_mode = Qt;
4431 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4432 doc: /* Non-nil if Tool-Bar mode is enabled.
4433 See the command `tool-bar-mode' for a description of this minor mode.
4434 Setting this variable directly does not take effect;
4435 either customize it (see the info node `Easy Customization')
4436 or call the function `tool-bar-mode'. */);
4437 #ifdef HAVE_WINDOW_SYSTEM
4438 Vtool_bar_mode = Qt;
4439 #else
4440 Vtool_bar_mode = Qnil;
4441 #endif
4443 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4444 doc: /* Minibufferless frames use this frame's minibuffer.
4446 Emacs cannot create minibufferless frames unless this is set to an
4447 appropriate surrogate.
4449 Emacs consults this variable only when creating minibufferless
4450 frames; once the frame is created, it sticks with its assigned
4451 minibuffer, no matter what this variable is set to. This means that
4452 this variable doesn't necessarily say anything meaningful about the
4453 current set of frames, or where the minibuffer is currently being
4454 displayed.
4456 This variable is local to the current terminal and cannot be buffer-local. */);
4458 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4459 doc: /* Non-nil if window system changes focus when you move the mouse.
4460 You should set this variable to tell Emacs how your window manager
4461 handles focus, since there is no way in general for Emacs to find out
4462 automatically. See also `mouse-autoselect-window'. */);
4463 focus_follows_mouse = 0;
4465 staticpro (&Vframe_list);
4467 defsubr (&Sframep);
4468 defsubr (&Sframe_live_p);
4469 defsubr (&Swindow_system);
4470 defsubr (&Smake_terminal_frame);
4471 defsubr (&Shandle_switch_frame);
4472 defsubr (&Sselect_frame);
4473 defsubr (&Sselected_frame);
4474 defsubr (&Sframe_list);
4475 defsubr (&Snext_frame);
4476 defsubr (&Sprevious_frame);
4477 defsubr (&Sdelete_frame);
4478 defsubr (&Smouse_position);
4479 defsubr (&Smouse_pixel_position);
4480 defsubr (&Sset_mouse_position);
4481 defsubr (&Sset_mouse_pixel_position);
4482 #if 0
4483 defsubr (&Sframe_configuration);
4484 defsubr (&Srestore_frame_configuration);
4485 #endif
4486 defsubr (&Smake_frame_visible);
4487 defsubr (&Smake_frame_invisible);
4488 defsubr (&Siconify_frame);
4489 defsubr (&Sframe_visible_p);
4490 defsubr (&Svisible_frame_list);
4491 defsubr (&Sraise_frame);
4492 defsubr (&Slower_frame);
4493 defsubr (&Sredirect_frame_focus);
4494 defsubr (&Sframe_focus);
4495 defsubr (&Sframe_parameters);
4496 defsubr (&Sframe_parameter);
4497 defsubr (&Smodify_frame_parameters);
4498 defsubr (&Sframe_char_height);
4499 defsubr (&Sframe_char_width);
4500 defsubr (&Sframe_pixel_height);
4501 defsubr (&Sframe_pixel_width);
4502 defsubr (&Stool_bar_pixel_width);
4503 defsubr (&Sset_frame_height);
4504 defsubr (&Sset_frame_width);
4505 defsubr (&Sset_frame_size);
4506 defsubr (&Sset_frame_position);
4507 defsubr (&Sframe_pointer_visible_p);
4509 #ifdef HAVE_WINDOW_SYSTEM
4510 defsubr (&Sx_get_resource);
4511 defsubr (&Sx_parse_geometry);
4512 #endif