* src/mem-limits.h: Remove duplicated includes.
[emacs.git] / src / frame.c
blobae8fdff807db8576b926a96bf410915e85b6608e
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009, 2010 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 <setjmp.h>
25 #include "lisp.h"
26 #include "character.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef HAVE_NS
34 #include "nsterm.h"
35 #endif
36 #include "buffer.h"
37 /* These help us bind and responding to switch-frame events. */
38 #include "commands.h"
39 #include "keyboard.h"
40 #include "frame.h"
41 #include "blockinput.h"
42 #include "termchar.h"
43 #include "termhooks.h"
44 #include "dispextern.h"
45 #include "window.h"
46 #include "font.h"
47 #ifdef HAVE_WINDOW_SYSTEM
48 #include "fontset.h"
49 #endif
50 #ifdef MSDOS
51 #include "msdos.h"
52 #include "dosfns.h"
53 #endif
56 /* If we shall make pointer invisible when typing or not. */
57 Lisp_Object Vmake_pointer_invisible;
59 #ifdef HAVE_WINDOW_SYSTEM
61 /* The name we're using in resource queries. Most often "emacs". */
63 Lisp_Object Vx_resource_name;
65 /* The application class we're using in resource queries.
66 Normally "Emacs". */
68 Lisp_Object Vx_resource_class;
70 /* Lower limit value of the frame opacity (alpha transparency). */
72 Lisp_Object Vframe_alpha_lower_limit;
74 #endif
76 #ifdef HAVE_NS
77 Lisp_Object Qns_parse_geometry;
78 #endif
80 Lisp_Object Qframep, Qframe_live_p;
81 Lisp_Object Qicon, Qmodeline;
82 Lisp_Object Qonly;
83 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
84 Lisp_Object Qvisible;
85 Lisp_Object Qdisplay_type;
86 Lisp_Object Qbackground_mode;
87 Lisp_Object Qnoelisp;
89 Lisp_Object Qx_frame_parameter;
90 Lisp_Object Qx_resource_name;
91 Lisp_Object Qterminal;
92 Lisp_Object Qterminal_live_p;
94 /* Frame parameters (set or reported). */
96 Lisp_Object Qauto_raise, Qauto_lower;
97 Lisp_Object Qborder_color, Qborder_width;
98 Lisp_Object Qcursor_color, Qcursor_type;
99 Lisp_Object Qgeometry; /* Not used */
100 Lisp_Object Qheight, Qwidth;
101 Lisp_Object Qleft, Qright;
102 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
103 Lisp_Object Qtooltip;
104 Lisp_Object Qinternal_border_width;
105 Lisp_Object Qmouse_color;
106 Lisp_Object Qminibuffer;
107 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
108 Lisp_Object Qvisibility;
109 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
110 Lisp_Object Qscreen_gamma;
111 Lisp_Object Qline_spacing;
112 Lisp_Object Quser_position, Quser_size;
113 Lisp_Object Qwait_for_wm;
114 Lisp_Object Qwindow_id;
115 #ifdef HAVE_X_WINDOWS
116 Lisp_Object Qouter_window_id;
117 #endif
118 Lisp_Object Qparent_id;
119 Lisp_Object Qtitle, Qname;
120 Lisp_Object Qexplicit_name;
121 Lisp_Object Qunsplittable;
122 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
123 Lisp_Object Vmenu_bar_mode, Vtool_bar_mode;
124 Lisp_Object Qleft_fringe, Qright_fringe;
125 Lisp_Object Qbuffer_predicate, Qbuffer_list, Qburied_buffer_list;
126 Lisp_Object Qtty_color_mode;
127 Lisp_Object Qtty, Qtty_type;
129 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
130 Lisp_Object Qsticky;
131 Lisp_Object Qfont_backend;
132 Lisp_Object Qalpha;
134 Lisp_Object Qface_set_after_frame_default;
136 Lisp_Object Vterminal_frame;
137 Lisp_Object Vdefault_frame_alist;
138 Lisp_Object Vdefault_frame_scroll_bars;
139 Lisp_Object Vmouse_position_function;
140 Lisp_Object Vmouse_highlight;
141 static Lisp_Object Vdelete_frame_functions, Qdelete_frame_functions;
143 int focus_follows_mouse;
145 static void
146 set_menu_bar_lines_1 (Lisp_Object window, int n)
148 struct window *w = XWINDOW (window);
150 XSETFASTINT (w->last_modified, 0);
151 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
152 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
154 if (INTEGERP (w->orig_top_line))
155 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
156 if (INTEGERP (w->orig_total_lines))
157 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
159 /* Handle just the top child in a vertical split. */
160 if (!NILP (w->vchild))
161 set_menu_bar_lines_1 (w->vchild, n);
163 /* Adjust all children in a horizontal split. */
164 for (window = w->hchild; !NILP (window); window = w->next)
166 w = XWINDOW (window);
167 set_menu_bar_lines_1 (window, n);
171 void
172 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
174 int nlines;
175 int olines = FRAME_MENU_BAR_LINES (f);
177 /* Right now, menu bars don't work properly in minibuf-only frames;
178 most of the commands try to apply themselves to the minibuffer
179 frame itself, and get an error because you can't switch buffers
180 in or split the minibuffer window. */
181 if (FRAME_MINIBUF_ONLY_P (f))
182 return;
184 if (INTEGERP (value))
185 nlines = XINT (value);
186 else
187 nlines = 0;
189 if (nlines != olines)
191 windows_or_buffers_changed++;
192 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
193 FRAME_MENU_BAR_LINES (f) = nlines;
194 set_menu_bar_lines_1 (f->root_window, nlines - olines);
195 adjust_glyphs (f);
199 Lisp_Object Vframe_list;
201 extern Lisp_Object Vminibuffer_list;
202 extern Lisp_Object get_minibuffer (int);
203 extern Lisp_Object Fhandle_switch_frame (Lisp_Object event);
204 extern Lisp_Object Fredirect_frame_focus (Lisp_Object frame, Lisp_Object focus_frame);
205 extern Lisp_Object x_get_focus_frame (struct frame *frame);
206 extern Lisp_Object QCname, Qfont_param;
209 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
210 doc: /* Return non-nil if OBJECT is a frame.
211 Value is t for a termcap frame (a character-only terminal),
212 `x' for an Emacs frame that is really an X window,
213 `w32' for an Emacs frame that is a window on MS-Windows display,
214 `ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
215 `pc' for a direct-write MS-DOS frame.
216 See also `frame-live-p'. */)
217 (Lisp_Object object)
219 if (!FRAMEP (object))
220 return Qnil;
221 switch (XFRAME (object)->output_method)
223 case output_initial: /* The initial frame is like a termcap frame. */
224 case output_termcap:
225 return Qt;
226 case output_x_window:
227 return Qx;
228 case output_w32:
229 return Qw32;
230 case output_msdos_raw:
231 return Qpc;
232 case output_mac:
233 return Qmac;
234 case output_ns:
235 return Qns;
236 default:
237 abort ();
241 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
242 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
243 Value is nil if OBJECT is not a live frame. If object is a live
244 frame, the return value indicates what sort of terminal device it is
245 displayed on. See the documentation of `framep' for possible
246 return values. */)
247 (Lisp_Object object)
249 return ((FRAMEP (object)
250 && FRAME_LIVE_P (XFRAME (object)))
251 ? Fframep (object)
252 : Qnil);
255 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
256 doc: /* The name of the window system that FRAME is displaying through.
257 The value is a symbol---for instance, 'x' for X windows.
258 The value is nil if Emacs is using a text-only terminal.
260 FRAME defaults to the currently selected frame. */)
261 (Lisp_Object frame)
263 Lisp_Object type;
264 if (NILP (frame))
265 frame = selected_frame;
267 type = Fframep (frame);
269 if (NILP (type))
270 wrong_type_argument (Qframep, frame);
272 if (EQ (type, Qt))
273 return Qnil;
274 else
275 return type;
278 struct frame *
279 make_frame (int mini_p)
281 Lisp_Object frame;
282 register struct frame *f;
283 register Lisp_Object root_window;
284 register Lisp_Object mini_window;
286 f = allocate_frame ();
287 XSETFRAME (frame, f);
289 f->desired_matrix = 0;
290 f->current_matrix = 0;
291 f->desired_pool = 0;
292 f->current_pool = 0;
293 f->glyphs_initialized_p = 0;
294 f->decode_mode_spec_buffer = 0;
295 f->visible = 0;
296 f->async_visible = 0;
297 f->output_data.nothing = 0;
298 f->iconified = 0;
299 f->async_iconified = 0;
300 f->wants_modeline = 1;
301 f->auto_raise = 0;
302 f->auto_lower = 0;
303 f->no_split = 0;
304 f->garbaged = 1;
305 f->has_minibuffer = mini_p;
306 f->focus_frame = Qnil;
307 f->explicit_name = 0;
308 f->can_have_scroll_bars = 0;
309 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
310 f->param_alist = Qnil;
311 f->scroll_bars = Qnil;
312 f->condemned_scroll_bars = Qnil;
313 f->face_alist = Qnil;
314 f->face_cache = NULL;
315 f->menu_bar_items = Qnil;
316 f->menu_bar_vector = Qnil;
317 f->menu_bar_items_used = 0;
318 f->buffer_predicate = Qnil;
319 f->buffer_list = Qnil;
320 f->buried_buffer_list = Qnil;
321 f->namebuf = 0;
322 f->title = Qnil;
323 f->menu_bar_window = Qnil;
324 f->tool_bar_window = Qnil;
325 f->tool_bar_items = Qnil;
326 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
327 f->n_tool_bar_items = 0;
328 f->left_fringe_width = f->right_fringe_width = 0;
329 f->fringe_cols = 0;
330 f->menu_bar_lines = 0;
331 f->tool_bar_lines = 0;
332 f->scroll_bar_actual_width = 0;
333 f->border_width = 0;
334 f->internal_border_width = 0;
335 f->column_width = 1; /* !FRAME_WINDOW_P value */
336 f->line_height = 1; /* !FRAME_WINDOW_P value */
337 f->x_pixels_diff = f->y_pixels_diff = 0;
338 #ifdef HAVE_WINDOW_SYSTEM
339 f->want_fullscreen = FULLSCREEN_NONE;
340 #endif
341 f->size_hint_flags = 0;
342 f->win_gravity = 0;
343 f->font_driver_list = NULL;
344 f->font_data_list = NULL;
346 root_window = make_window ();
347 if (mini_p)
349 mini_window = make_window ();
350 XWINDOW (root_window)->next = mini_window;
351 XWINDOW (mini_window)->prev = root_window;
352 XWINDOW (mini_window)->mini_p = Qt;
353 XWINDOW (mini_window)->frame = frame;
354 f->minibuffer_window = mini_window;
356 else
358 mini_window = Qnil;
359 XWINDOW (root_window)->next = Qnil;
360 f->minibuffer_window = Qnil;
363 XWINDOW (root_window)->frame = frame;
365 /* 10 is arbitrary,
366 just so that there is "something there."
367 Correct size will be set up later with change_frame_size. */
369 SET_FRAME_COLS (f, 10);
370 FRAME_LINES (f) = 10;
372 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
373 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
375 if (mini_p)
377 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
378 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
379 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
382 /* Choose a buffer for the frame's root window. */
384 Lisp_Object buf;
386 XWINDOW (root_window)->buffer = Qt;
387 buf = Fcurrent_buffer ();
388 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
389 a space), try to find another one. */
390 if (SREF (Fbuffer_name (buf), 0) == ' ')
391 buf = Fother_buffer (buf, Qnil, Qnil);
393 /* Use set_window_buffer, not Fset_window_buffer, and don't let
394 hooks be run by it. The reason is that the whole frame/window
395 arrangement is not yet fully intialized at this point. Windows
396 don't have the right size, glyph matrices aren't initialized
397 etc. Running Lisp functions at this point surely ends in a
398 SEGV. */
399 set_window_buffer (root_window, buf, 0, 0);
400 f->buffer_list = Fcons (buf, Qnil);
403 if (mini_p)
405 XWINDOW (mini_window)->buffer = Qt;
406 set_window_buffer (mini_window,
407 (NILP (Vminibuffer_list)
408 ? get_minibuffer (0)
409 : Fcar (Vminibuffer_list)),
410 0, 0);
413 f->root_window = root_window;
414 f->selected_window = root_window;
415 /* Make sure this window seems more recently used than
416 a newly-created, never-selected window. */
417 ++window_select_count;
418 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
420 f->default_face_done_p = 0;
422 return f;
425 #ifdef HAVE_WINDOW_SYSTEM
426 /* Make a frame using a separate minibuffer window on another frame.
427 MINI_WINDOW is the minibuffer window to use. nil means use the
428 default (the global minibuffer). */
430 struct frame *
431 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
433 register struct frame *f;
434 struct gcpro gcpro1;
436 if (!NILP (mini_window))
437 CHECK_LIVE_WINDOW (mini_window);
439 if (!NILP (mini_window)
440 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
441 error ("Frame and minibuffer must be on the same terminal");
443 /* Make a frame containing just a root window. */
444 f = make_frame (0);
446 if (NILP (mini_window))
448 /* Use default-minibuffer-frame if possible. */
449 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
450 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
452 Lisp_Object frame_dummy;
454 XSETFRAME (frame_dummy, f);
455 GCPRO1 (frame_dummy);
456 /* If there's no minibuffer frame to use, create one. */
457 kb->Vdefault_minibuffer_frame =
458 call1 (intern ("make-initial-minibuffer-frame"), display);
459 UNGCPRO;
462 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
465 f->minibuffer_window = mini_window;
467 /* Make the chosen minibuffer window display the proper minibuffer,
468 unless it is already showing a minibuffer. */
469 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
470 Fset_window_buffer (mini_window,
471 (NILP (Vminibuffer_list)
472 ? get_minibuffer (0)
473 : Fcar (Vminibuffer_list)), Qnil);
474 return f;
477 /* Make a frame containing only a minibuffer window. */
479 struct frame *
480 make_minibuffer_frame (void)
482 /* First make a frame containing just a root window, no minibuffer. */
484 register struct frame *f = make_frame (0);
485 register Lisp_Object mini_window;
486 register Lisp_Object frame;
488 XSETFRAME (frame, f);
490 f->auto_raise = 0;
491 f->auto_lower = 0;
492 f->no_split = 1;
493 f->wants_modeline = 0;
494 f->has_minibuffer = 1;
496 /* Now label the root window as also being the minibuffer.
497 Avoid infinite looping on the window chain by marking next pointer
498 as nil. */
500 mini_window = f->minibuffer_window = f->root_window;
501 XWINDOW (mini_window)->mini_p = Qt;
502 XWINDOW (mini_window)->next = Qnil;
503 XWINDOW (mini_window)->prev = Qnil;
504 XWINDOW (mini_window)->frame = frame;
506 /* Put the proper buffer in that window. */
508 Fset_window_buffer (mini_window,
509 (NILP (Vminibuffer_list)
510 ? get_minibuffer (0)
511 : Fcar (Vminibuffer_list)), Qnil);
512 return f;
514 #endif /* HAVE_WINDOW_SYSTEM */
516 /* Construct a frame that refers to a terminal. */
518 static int tty_frame_count;
520 struct frame *
521 make_initial_frame (void)
523 struct frame *f;
524 struct terminal *terminal;
525 Lisp_Object frame;
527 eassert (initial_kboard);
529 /* The first call must initialize Vframe_list. */
530 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
531 Vframe_list = Qnil;
533 terminal = init_initial_terminal ();
535 f = make_frame (1);
536 XSETFRAME (frame, f);
538 Vframe_list = Fcons (frame, Vframe_list);
540 tty_frame_count = 1;
541 f->name = make_pure_c_string ("F1");
543 f->visible = 1;
544 f->async_visible = 1;
546 f->output_method = terminal->type;
547 f->terminal = terminal;
548 f->terminal->reference_count++;
549 f->output_data.nothing = 0;
551 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
552 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
554 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
555 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
557 /* The default value of menu-bar-mode is t. */
558 set_menu_bar_lines (f, make_number (1), Qnil);
560 #ifdef CANNOT_DUMP
561 if (!noninteractive)
562 init_frame_faces (f);
563 #endif
565 return f;
569 struct frame *
570 make_terminal_frame (struct terminal *terminal)
572 register struct frame *f;
573 Lisp_Object frame;
574 char name[20];
576 if (!terminal->name)
577 error ("Terminal is not live, can't create new frames on it");
579 f = make_frame (1);
581 XSETFRAME (frame, f);
582 Vframe_list = Fcons (frame, Vframe_list);
584 tty_frame_count++;
585 sprintf (name, "F%d", tty_frame_count);
586 f->name = build_string (name);
588 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
589 f->async_visible = 1; /* Don't let visible be cleared later. */
590 f->terminal = terminal;
591 f->terminal->reference_count++;
592 #ifdef MSDOS
593 f->output_data.tty->display_info = &the_only_display_info;
594 if (!inhibit_window_system
595 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
596 || XFRAME (selected_frame)->output_method == output_msdos_raw))
597 f->output_method = output_msdos_raw;
598 else
599 f->output_method = output_termcap;
600 #else /* not MSDOS */
601 f->output_method = output_termcap;
602 create_tty_output (f);
603 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
604 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
605 #endif /* not MSDOS */
607 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
608 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
609 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
611 /* Set the top frame to the newly created frame. */
612 if (FRAMEP (FRAME_TTY (f)->top_frame)
613 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
614 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
616 FRAME_TTY (f)->top_frame = frame;
618 if (!noninteractive)
619 init_frame_faces (f);
621 return f;
624 /* Get a suitable value for frame parameter PARAMETER for a newly
625 created frame, based on (1) the user-supplied frame parameter
626 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
628 static Lisp_Object
629 get_future_frame_param (Lisp_Object parameter,
630 Lisp_Object supplied_parms,
631 char *current_value)
633 Lisp_Object result;
635 result = Fassq (parameter, supplied_parms);
636 if (NILP (result))
637 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
638 if (NILP (result) && current_value != NULL)
639 result = build_string (current_value);
640 if (!NILP (result) && !STRINGP (result))
641 result = XCDR (result);
642 if (NILP (result) || !STRINGP (result))
643 result = Qnil;
645 return result;
648 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
649 1, 1, 0,
650 doc: /* Create an additional terminal frame, possibly on another terminal.
651 This function takes one argument, an alist specifying frame parameters.
653 You can create multiple frames on a single text-only terminal, but
654 only one of them (the selected terminal frame) is actually displayed.
656 In practice, generally you don't need to specify any parameters,
657 except when you want to create a new frame on another terminal.
658 In that case, the `tty' parameter specifies the device file to open,
659 and the `tty-type' parameter specifies the terminal type. Example:
661 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
663 Note that changing the size of one terminal frame automatically
664 affects all frames on the same terminal device. */)
665 (Lisp_Object parms)
667 struct frame *f;
668 struct terminal *t = NULL;
669 Lisp_Object frame, tem;
670 struct frame *sf = SELECTED_FRAME ();
672 #ifdef MSDOS
673 if (sf->output_method != output_msdos_raw
674 && sf->output_method != output_termcap)
675 abort ();
676 #else /* not MSDOS */
678 #ifdef WINDOWSNT /* This should work now! */
679 if (sf->output_method != output_termcap)
680 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
681 #endif
682 #endif /* not MSDOS */
685 Lisp_Object terminal;
687 terminal = Fassq (Qterminal, parms);
688 if (!NILP (terminal))
690 terminal = XCDR (terminal);
691 t = get_terminal (terminal, 1);
693 #ifdef MSDOS
694 if (t && t != the_only_display_info.terminal)
695 /* msdos.c assumes a single tty_display_info object. */
696 error ("Multiple terminals are not supported on this platform");
697 if (!t)
698 t = the_only_display_info.terminal;
699 #endif
702 if (!t)
704 char *name = 0, *type = 0;
705 Lisp_Object tty, tty_type;
707 tty = get_future_frame_param
708 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
709 ? FRAME_TTY (XFRAME (selected_frame))->name
710 : NULL));
711 if (!NILP (tty))
713 name = (char *) alloca (SBYTES (tty) + 1);
714 strncpy (name, SDATA (tty), SBYTES (tty));
715 name[SBYTES (tty)] = 0;
718 tty_type = get_future_frame_param
719 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
720 ? FRAME_TTY (XFRAME (selected_frame))->type
721 : NULL));
722 if (!NILP (tty_type))
724 type = (char *) alloca (SBYTES (tty_type) + 1);
725 strncpy (type, SDATA (tty_type), SBYTES (tty_type));
726 type[SBYTES (tty_type)] = 0;
729 t = init_tty (name, type, 0); /* Errors are not fatal. */
732 f = make_terminal_frame (t);
735 int width, height;
736 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
737 change_frame_size (f, height, width, 0, 0, 0);
740 adjust_glyphs (f);
741 calculate_costs (f);
742 XSETFRAME (frame, f);
743 Fmodify_frame_parameters (frame, parms);
744 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
745 build_string (t->display_info.tty->type)),
746 Qnil));
747 if (t->display_info.tty->name != NULL)
748 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
749 build_string (t->display_info.tty->name)),
750 Qnil));
751 else
752 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
754 /* Make the frame face alist be frame-specific, so that each
755 frame could change its face definitions independently. */
756 f->face_alist = Fcopy_alist (sf->face_alist);
757 /* Simple Fcopy_alist isn't enough, because we need the contents of
758 the vectors which are the CDRs of associations in face_alist to
759 be copied as well. */
760 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
761 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
762 return frame;
766 /* Perform the switch to frame FRAME.
768 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
769 FRAME1 as frame.
771 If TRACK is non-zero and the frame that currently has the focus
772 redirects its focus to the selected frame, redirect that focused
773 frame's focus to FRAME instead.
775 FOR_DELETION non-zero means that the selected frame is being
776 deleted, which includes the possibility that the frame's terminal
777 is dead.
779 The value of NORECORD is passed as argument to Fselect_window. */
781 Lisp_Object
782 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
784 struct frame *sf = SELECTED_FRAME ();
786 /* If FRAME is a switch-frame event, extract the frame we should
787 switch to. */
788 if (CONSP (frame)
789 && EQ (XCAR (frame), Qswitch_frame)
790 && CONSP (XCDR (frame)))
791 frame = XCAR (XCDR (frame));
793 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
794 a switch-frame event to arrive after a frame is no longer live,
795 especially when deleting the initial frame during startup. */
796 CHECK_FRAME (frame);
797 if (! FRAME_LIVE_P (XFRAME (frame)))
798 return Qnil;
800 if (sf == XFRAME (frame))
801 return frame;
803 /* This is too greedy; it causes inappropriate focus redirection
804 that's hard to get rid of. */
805 #if 0
806 /* If a frame's focus has been redirected toward the currently
807 selected frame, we should change the redirection to point to the
808 newly selected frame. This means that if the focus is redirected
809 from a minibufferless frame to a surrogate minibuffer frame, we
810 can use `other-window' to switch between all the frames using
811 that minibuffer frame, and the focus redirection will follow us
812 around. */
813 if (track)
815 Lisp_Object tail;
817 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
819 Lisp_Object focus;
821 if (!FRAMEP (XCAR (tail)))
822 abort ();
824 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
826 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
827 Fredirect_frame_focus (XCAR (tail), frame);
830 #else /* ! 0 */
831 /* Instead, apply it only to the frame we're pointing to. */
832 #ifdef HAVE_WINDOW_SYSTEM
833 if (track && FRAME_WINDOW_P (XFRAME (frame)))
835 Lisp_Object focus, xfocus;
837 xfocus = x_get_focus_frame (XFRAME (frame));
838 if (FRAMEP (xfocus))
840 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
841 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
842 Fredirect_frame_focus (xfocus, frame);
845 #endif /* HAVE_X_WINDOWS */
846 #endif /* ! 0 */
848 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
849 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
851 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
853 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
854 /* Mark previously displayed frame as now obscured. */
855 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
856 XFRAME (frame)->async_visible = 1;
857 FRAME_TTY (XFRAME (frame))->top_frame = frame;
860 selected_frame = frame;
861 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
862 last_nonminibuf_frame = XFRAME (selected_frame);
864 Fselect_window (XFRAME (frame)->selected_window, norecord);
866 /* We want to make sure that the next event generates a frame-switch
867 event to the appropriate frame. This seems kludgy to me, but
868 before you take it out, make sure that evaluating something like
869 (select-window (frame-root-window (new-frame))) doesn't end up
870 with your typing being interpreted in the new frame instead of
871 the one you're actually typing in. */
872 internal_last_event_frame = Qnil;
874 return frame;
877 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
878 doc: /* Select FRAME.
879 Subsequent editing commands apply to its selected window.
880 Optional argument NORECORD means to neither change the order of
881 recently selected windows nor the buffer list.
883 The selection of FRAME lasts until the next time the user does
884 something to select a different frame, or until the next time
885 this function is called. If you are using a window system, the
886 previously selected frame may be restored as the selected frame
887 when returning to the command loop, because it still may have
888 the window system's input focus. On a text-only terminal, the
889 next redisplay will display FRAME.
891 This function returns FRAME, or nil if FRAME has been deleted. */)
892 (Lisp_Object frame, Lisp_Object norecord)
894 return do_switch_frame (frame, 1, 0, norecord);
898 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
899 doc: /* Handle a switch-frame event EVENT.
900 Switch-frame events are usually bound to this function.
901 A switch-frame event tells Emacs that the window manager has requested
902 that the user's events be directed to the frame mentioned in the event.
903 This function selects the selected window of the frame of EVENT.
905 If EVENT is frame object, handle it as if it were a switch-frame event
906 to that frame. */)
907 (Lisp_Object event)
909 /* Preserve prefix arg that the command loop just cleared. */
910 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
911 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
912 return do_switch_frame (event, 0, 0, Qnil);
915 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
916 doc: /* Return the frame that is now selected. */)
917 (void)
919 return selected_frame;
922 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
923 doc: /* Return the frame object that window WINDOW is on. */)
924 (Lisp_Object window)
926 CHECK_LIVE_WINDOW (window);
927 return XWINDOW (window)->frame;
930 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
931 doc: /* Returns the topmost, leftmost window of FRAME.
932 If omitted, FRAME defaults to the currently selected frame. */)
933 (Lisp_Object frame)
935 Lisp_Object w;
937 if (NILP (frame))
938 w = SELECTED_FRAME ()->root_window;
939 else
941 CHECK_LIVE_FRAME (frame);
942 w = XFRAME (frame)->root_window;
944 while (NILP (XWINDOW (w)->buffer))
946 if (! NILP (XWINDOW (w)->hchild))
947 w = XWINDOW (w)->hchild;
948 else if (! NILP (XWINDOW (w)->vchild))
949 w = XWINDOW (w)->vchild;
950 else
951 abort ();
953 return w;
956 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
957 Sactive_minibuffer_window, 0, 0, 0,
958 doc: /* Return the currently active minibuffer window, or nil if none. */)
959 (void)
961 return minibuf_level ? minibuf_window : Qnil;
964 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
965 doc: /* Returns the root-window of FRAME.
966 If omitted, FRAME defaults to the currently selected frame. */)
967 (Lisp_Object frame)
969 Lisp_Object window;
971 if (NILP (frame))
972 window = SELECTED_FRAME ()->root_window;
973 else
975 CHECK_LIVE_FRAME (frame);
976 window = XFRAME (frame)->root_window;
979 return window;
982 DEFUN ("frame-selected-window", Fframe_selected_window,
983 Sframe_selected_window, 0, 1, 0,
984 doc: /* Return the selected window of FRAME.
985 FRAME defaults to the currently selected frame. */)
986 (Lisp_Object frame)
988 Lisp_Object window;
990 if (NILP (frame))
991 window = SELECTED_FRAME ()->selected_window;
992 else
994 CHECK_LIVE_FRAME (frame);
995 window = XFRAME (frame)->selected_window;
998 return window;
1001 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
1002 Sset_frame_selected_window, 2, 3, 0,
1003 doc: /* Set selected window of FRAME to WINDOW.
1004 If FRAME is nil, use the selected frame. If FRAME is the
1005 selected frame, this makes WINDOW the selected window.
1006 Optional argument NORECORD non-nil means to neither change the
1007 order of recently selected windows nor the buffer list.
1008 Return WINDOW. */)
1009 (Lisp_Object frame, Lisp_Object window, Lisp_Object norecord)
1011 if (NILP (frame))
1012 frame = selected_frame;
1014 CHECK_LIVE_FRAME (frame);
1015 CHECK_LIVE_WINDOW (window);
1017 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
1018 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
1020 if (EQ (frame, selected_frame))
1021 return Fselect_window (window, norecord);
1023 return XFRAME (frame)->selected_window = window;
1027 DEFUN ("frame-list", Fframe_list, Sframe_list,
1028 0, 0, 0,
1029 doc: /* Return a list of all live frames. */)
1030 (void)
1032 Lisp_Object frames;
1033 frames = Fcopy_sequence (Vframe_list);
1034 #ifdef HAVE_WINDOW_SYSTEM
1035 if (FRAMEP (tip_frame))
1036 frames = Fdelq (tip_frame, frames);
1037 #endif
1038 return frames;
1041 /* Return the next frame in the frame list after FRAME.
1042 If MINIBUF is nil, exclude minibuffer-only frames.
1043 If MINIBUF is a window, include only its own frame
1044 and any frame now using that window as the minibuffer.
1045 If MINIBUF is `visible', include all visible frames.
1046 If MINIBUF is 0, include all visible and iconified frames.
1047 Otherwise, include all frames. */
1049 static Lisp_Object
1050 next_frame (Lisp_Object frame, Lisp_Object minibuf)
1052 Lisp_Object tail;
1053 int passed = 0;
1055 /* There must always be at least one frame in Vframe_list. */
1056 if (! CONSP (Vframe_list))
1057 abort ();
1059 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
1060 forever. Forestall that. */
1061 CHECK_LIVE_FRAME (frame);
1063 while (1)
1064 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1066 Lisp_Object f;
1068 f = XCAR (tail);
1070 if (passed
1071 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1072 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1073 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1074 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
1076 /* Decide whether this frame is eligible to be returned. */
1078 /* If we've looped all the way around without finding any
1079 eligible frames, return the original frame. */
1080 if (EQ (f, frame))
1081 return f;
1083 /* Let minibuf decide if this frame is acceptable. */
1084 if (NILP (minibuf))
1086 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1087 return f;
1089 else if (EQ (minibuf, Qvisible))
1091 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1092 if (FRAME_VISIBLE_P (XFRAME (f)))
1093 return f;
1095 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
1097 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1098 if (FRAME_VISIBLE_P (XFRAME (f))
1099 || FRAME_ICONIFIED_P (XFRAME (f)))
1100 return f;
1102 else if (WINDOWP (minibuf))
1104 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1105 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1106 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1107 FRAME_FOCUS_FRAME (XFRAME (f))))
1108 return f;
1110 else
1111 return f;
1114 if (EQ (frame, f))
1115 passed++;
1119 /* Return the previous frame in the frame list before FRAME.
1120 If MINIBUF is nil, exclude minibuffer-only frames.
1121 If MINIBUF is a window, include only its own frame
1122 and any frame now using that window as the minibuffer.
1123 If MINIBUF is `visible', include all visible frames.
1124 If MINIBUF is 0, include all visible and iconified frames.
1125 Otherwise, include all frames. */
1127 static Lisp_Object
1128 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
1130 Lisp_Object tail;
1131 Lisp_Object prev;
1133 /* There must always be at least one frame in Vframe_list. */
1134 if (! CONSP (Vframe_list))
1135 abort ();
1137 prev = Qnil;
1138 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1140 Lisp_Object f;
1142 f = XCAR (tail);
1143 if (!FRAMEP (f))
1144 abort ();
1146 if (EQ (frame, f) && !NILP (prev))
1147 return prev;
1149 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
1150 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1151 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
1152 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
1154 /* Decide whether this frame is eligible to be returned,
1155 according to minibuf. */
1156 if (NILP (minibuf))
1158 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1159 prev = f;
1161 else if (WINDOWP (minibuf))
1163 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1164 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1165 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1166 FRAME_FOCUS_FRAME (XFRAME (f))))
1167 prev = f;
1169 else if (EQ (minibuf, Qvisible))
1171 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1172 if (FRAME_VISIBLE_P (XFRAME (f)))
1173 prev = f;
1175 else if (XFASTINT (minibuf) == 0)
1177 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1178 if (FRAME_VISIBLE_P (XFRAME (f))
1179 || FRAME_ICONIFIED_P (XFRAME (f)))
1180 prev = f;
1182 else
1183 prev = f;
1187 /* We've scanned the entire list. */
1188 if (NILP (prev))
1189 /* We went through the whole frame list without finding a single
1190 acceptable frame. Return the original frame. */
1191 return frame;
1192 else
1193 /* There were no acceptable frames in the list before FRAME; otherwise,
1194 we would have returned directly from the loop. Since PREV is the last
1195 acceptable frame in the list, return it. */
1196 return prev;
1200 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1201 doc: /* Return the next frame in the frame list after FRAME.
1202 It considers only frames on the same terminal as FRAME.
1203 By default, skip minibuffer-only frames.
1204 If omitted, FRAME defaults to the selected frame.
1205 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1206 If MINIFRAME is a window, include only its own frame
1207 and any frame now using that window as the minibuffer.
1208 If MINIFRAME is `visible', include all visible frames.
1209 If MINIFRAME is 0, include all visible and iconified frames.
1210 Otherwise, include all frames. */)
1211 (Lisp_Object frame, Lisp_Object miniframe)
1213 if (NILP (frame))
1214 frame = selected_frame;
1216 CHECK_LIVE_FRAME (frame);
1217 return next_frame (frame, miniframe);
1220 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1221 doc: /* Return the previous frame in the frame list before FRAME.
1222 It considers only frames on the same terminal as FRAME.
1223 By default, skip minibuffer-only frames.
1224 If omitted, FRAME defaults to the selected frame.
1225 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1226 If MINIFRAME is a window, include only its own frame
1227 and any frame now using that window as the minibuffer.
1228 If MINIFRAME is `visible', include all visible frames.
1229 If MINIFRAME is 0, include all visible and iconified frames.
1230 Otherwise, include all frames. */)
1231 (Lisp_Object frame, Lisp_Object miniframe)
1233 if (NILP (frame))
1234 frame = selected_frame;
1235 CHECK_LIVE_FRAME (frame);
1236 return prev_frame (frame, miniframe);
1239 /* Return 1 if it is ok to delete frame F;
1240 0 if all frames aside from F are invisible.
1241 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1244 other_visible_frames (FRAME_PTR f)
1246 /* We know the selected frame is visible,
1247 so if F is some other frame, it can't be the sole visible one. */
1248 if (f == SELECTED_FRAME ())
1250 Lisp_Object frames;
1251 int count = 0;
1253 for (frames = Vframe_list;
1254 CONSP (frames);
1255 frames = XCDR (frames))
1257 Lisp_Object this;
1259 this = XCAR (frames);
1260 /* Verify that the frame's window still exists
1261 and we can still talk to it. And note any recent change
1262 in visibility. */
1263 #ifdef HAVE_WINDOW_SYSTEM
1264 if (FRAME_WINDOW_P (XFRAME (this)))
1266 x_sync (XFRAME (this));
1267 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1269 #endif
1271 if (FRAME_VISIBLE_P (XFRAME (this))
1272 || FRAME_ICONIFIED_P (XFRAME (this))
1273 /* Allow deleting the terminal frame when at least
1274 one X frame exists! */
1275 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1276 count++;
1278 return count > 1;
1280 return 1;
1283 extern Lisp_Object Qrun_hook_with_args;
1285 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1286 unconditionally. x_connection_closed and delete_terminal use
1287 this. Any other value of FORCE implements the semantics
1288 described for Fdelete_frame. */
1289 Lisp_Object
1290 delete_frame (Lisp_Object frame, Lisp_Object force)
1291 /* If we use `register' here, gcc-4.0.2 on amd64 using
1292 -DUSE_LISP_UNION_TYPE complains further down that we're getting the
1293 address of `force'. Go figure. */
1296 struct frame *f;
1297 struct frame *sf = SELECTED_FRAME ();
1298 struct kboard *kb;
1300 int minibuffer_selected, tooltip_frame;
1302 if (EQ (frame, Qnil))
1304 f = sf;
1305 XSETFRAME (frame, f);
1307 else
1309 CHECK_FRAME (frame);
1310 f = XFRAME (frame);
1313 if (! FRAME_LIVE_P (f))
1314 return Qnil;
1316 if (NILP (force) && !other_visible_frames (f))
1317 error ("Attempt to delete the sole visible or iconified frame");
1319 /* x_connection_closed must have set FORCE to `noelisp' in order
1320 to delete the last frame, if it is gone. */
1321 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1322 error ("Attempt to delete the only frame");
1324 /* Does this frame have a minibuffer, and is it the surrogate
1325 minibuffer for any other frame? */
1326 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1328 Lisp_Object frames;
1330 for (frames = Vframe_list;
1331 CONSP (frames);
1332 frames = XCDR (frames))
1334 Lisp_Object this;
1335 this = XCAR (frames);
1337 if (! EQ (this, frame)
1338 && EQ (frame,
1339 WINDOW_FRAME (XWINDOW
1340 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1342 /* If we MUST delete this frame, delete the other first.
1343 But do this only if FORCE equals `noelisp'. */
1344 if (EQ (force, Qnoelisp))
1345 delete_frame (this, Qnoelisp);
1346 else
1347 error ("Attempt to delete a surrogate minibuffer frame");
1352 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1354 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1355 frame is a tooltip. FORCE is set to `noelisp' when handling
1356 a disconnect from the terminal, so we don't dare call Lisp
1357 code. */
1358 if (NILP (Vrun_hooks) || tooltip_frame)
1360 else if (EQ (force, Qnoelisp))
1361 pending_funcalls
1362 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1363 pending_funcalls);
1364 else
1365 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1367 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1368 if (! FRAME_LIVE_P (f))
1369 return Qnil;
1371 /* At this point, we are committed to deleting the frame.
1372 There is no more chance for errors to prevent it. */
1374 minibuffer_selected = EQ (minibuf_window, selected_window);
1376 /* Don't let the frame remain selected. */
1377 if (f == sf)
1379 Lisp_Object tail, frame1;
1381 /* Look for another visible frame on the same terminal. */
1382 frame1 = next_frame (frame, Qvisible);
1384 /* If there is none, find *some* other frame. */
1385 if (NILP (frame1) || EQ (frame1, frame))
1387 FOR_EACH_FRAME (tail, frame1)
1389 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1390 break;
1393 #ifdef NS_IMPL_COCOA
1394 else
1395 /* Under NS, there is no system mechanism for choosing a new
1396 window to get focus -- it is left to application code.
1397 So the portion of THIS application interfacing with NS
1398 needs to know about it. We call Fraise_frame, but the
1399 purpose is really to transfer focus. */
1400 Fraise_frame (frame1);
1401 #endif
1403 do_switch_frame (frame1, 0, 1, Qnil);
1404 sf = SELECTED_FRAME ();
1407 /* Don't allow minibuf_window to remain on a deleted frame. */
1408 if (EQ (f->minibuffer_window, minibuf_window))
1410 Fset_window_buffer (sf->minibuffer_window,
1411 XWINDOW (minibuf_window)->buffer, Qnil);
1412 minibuf_window = sf->minibuffer_window;
1414 /* If the dying minibuffer window was selected,
1415 select the new one. */
1416 if (minibuffer_selected)
1417 Fselect_window (minibuf_window, Qnil);
1420 /* Don't let echo_area_window to remain on a deleted frame. */
1421 if (EQ (f->minibuffer_window, echo_area_window))
1422 echo_area_window = sf->minibuffer_window;
1424 /* Clear any X selections for this frame. */
1425 #ifdef HAVE_X_WINDOWS
1426 if (FRAME_X_P (f))
1427 x_clear_frame_selections (f);
1428 #endif
1430 /* Free glyphs.
1431 This function must be called before the window tree of the
1432 frame is deleted because windows contain dynamically allocated
1433 memory. */
1434 free_glyphs (f);
1436 #ifdef HAVE_WINDOW_SYSTEM
1437 /* Give chance to each font driver to free a frame specific data. */
1438 font_update_drivers (f, Qnil);
1439 #endif
1441 /* Mark all the windows that used to be on FRAME as deleted, and then
1442 remove the reference to them. */
1443 delete_all_subwindows (XWINDOW (f->root_window));
1444 f->root_window = Qnil;
1446 Vframe_list = Fdelq (frame, Vframe_list);
1447 FRAME_SET_VISIBLE (f, 0);
1449 /* Allow the vector of menu bar contents to be freed in the next
1450 garbage collection. The frame object itself may not be garbage
1451 collected until much later, because recent_keys and other data
1452 structures can still refer to it. */
1453 f->menu_bar_vector = Qnil;
1455 free_font_driver_list (f);
1456 xfree (f->namebuf);
1457 xfree (f->decode_mode_spec_buffer);
1458 xfree (FRAME_INSERT_COST (f));
1459 xfree (FRAME_DELETEN_COST (f));
1460 xfree (FRAME_INSERTN_COST (f));
1461 xfree (FRAME_DELETE_COST (f));
1462 xfree (FRAME_MESSAGE_BUF (f));
1464 /* Since some events are handled at the interrupt level, we may get
1465 an event for f at any time; if we zero out the frame's terminal
1466 now, then we may trip up the event-handling code. Instead, we'll
1467 promise that the terminal of the frame must be valid until we
1468 have called the window-system-dependent frame destruction
1469 routine. */
1471 if (FRAME_TERMINAL (f)->delete_frame_hook)
1472 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1475 struct terminal *terminal = FRAME_TERMINAL (f);
1476 f->output_data.nothing = 0;
1477 f->terminal = 0; /* Now the frame is dead. */
1479 /* If needed, delete the terminal that this frame was on.
1480 (This must be done after the frame is killed.) */
1481 terminal->reference_count--;
1482 if (terminal->reference_count == 0)
1484 Lisp_Object tmp;
1485 XSETTERMINAL (tmp, terminal);
1487 kb = NULL;
1488 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1490 else
1491 kb = terminal->kboard;
1494 /* If we've deleted the last_nonminibuf_frame, then try to find
1495 another one. */
1496 if (f == last_nonminibuf_frame)
1498 Lisp_Object frames;
1500 last_nonminibuf_frame = 0;
1502 for (frames = Vframe_list;
1503 CONSP (frames);
1504 frames = XCDR (frames))
1506 f = XFRAME (XCAR (frames));
1507 if (!FRAME_MINIBUF_ONLY_P (f))
1509 last_nonminibuf_frame = f;
1510 break;
1515 /* If there's no other frame on the same kboard, get out of
1516 single-kboard state if we're in it for this kboard. */
1517 if (kb != NULL)
1519 Lisp_Object frames;
1520 /* Some frame we found on the same kboard, or nil if there are none. */
1521 Lisp_Object frame_on_same_kboard;
1523 frame_on_same_kboard = Qnil;
1525 for (frames = Vframe_list;
1526 CONSP (frames);
1527 frames = XCDR (frames))
1529 Lisp_Object this;
1530 struct frame *f1;
1532 this = XCAR (frames);
1533 if (!FRAMEP (this))
1534 abort ();
1535 f1 = XFRAME (this);
1537 if (kb == FRAME_KBOARD (f1))
1538 frame_on_same_kboard = this;
1541 if (NILP (frame_on_same_kboard))
1542 not_single_kboard_state (kb);
1546 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1547 find another one. Prefer minibuffer-only frames, but also notice
1548 frames with other windows. */
1549 if (kb != NULL && EQ (frame, kb->Vdefault_minibuffer_frame))
1551 Lisp_Object frames;
1553 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1554 Lisp_Object frame_with_minibuf;
1555 /* Some frame we found on the same kboard, or nil if there are none. */
1556 Lisp_Object frame_on_same_kboard;
1558 frame_on_same_kboard = Qnil;
1559 frame_with_minibuf = Qnil;
1561 for (frames = Vframe_list;
1562 CONSP (frames);
1563 frames = XCDR (frames))
1565 Lisp_Object this;
1566 struct frame *f1;
1568 this = XCAR (frames);
1569 if (!FRAMEP (this))
1570 abort ();
1571 f1 = XFRAME (this);
1573 /* Consider only frames on the same kboard
1574 and only those with minibuffers. */
1575 if (kb == FRAME_KBOARD (f1)
1576 && FRAME_HAS_MINIBUF_P (f1))
1578 frame_with_minibuf = this;
1579 if (FRAME_MINIBUF_ONLY_P (f1))
1580 break;
1583 if (kb == FRAME_KBOARD (f1))
1584 frame_on_same_kboard = this;
1587 if (!NILP (frame_on_same_kboard))
1589 /* We know that there must be some frame with a minibuffer out
1590 there. If this were not true, all of the frames present
1591 would have to be minibufferless, which implies that at some
1592 point their minibuffer frames must have been deleted, but
1593 that is prohibited at the top; you can't delete surrogate
1594 minibuffer frames. */
1595 if (NILP (frame_with_minibuf))
1596 abort ();
1598 kb->Vdefault_minibuffer_frame = frame_with_minibuf;
1600 else
1601 /* No frames left on this kboard--say no minibuffer either. */
1602 kb->Vdefault_minibuffer_frame = Qnil;
1605 /* Cause frame titles to update--necessary if we now have just one frame. */
1606 if (!tooltip_frame)
1607 update_mode_lines = 1;
1609 return Qnil;
1612 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1613 doc: /* Delete FRAME, permanently eliminating it from use.
1614 FRAME defaults to the selected frame.
1616 A frame may not be deleted if its minibuffer is used by other frames.
1617 Normally, you may not delete a frame if all other frames are invisible,
1618 but if the second optional argument FORCE is non-nil, you may do so.
1620 This function runs `delete-frame-functions' before actually
1621 deleting the frame, unless the frame is a tooltip.
1622 The functions are run with one argument, the frame to be deleted. */)
1623 (Lisp_Object frame, Lisp_Object force)
1625 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1629 /* Return mouse position in character cell units. */
1631 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1632 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1633 The position is given in character cells, where (0, 0) is the
1634 upper-left corner of the frame, X is the horizontal offset, and Y is
1635 the vertical offset.
1636 If Emacs is running on a mouseless terminal or hasn't been programmed
1637 to read the mouse position, it returns the selected frame for FRAME
1638 and nil for X and Y.
1639 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1640 passing the normal return value to that function as an argument,
1641 and returns whatever that function returns. */)
1642 (void)
1644 FRAME_PTR f;
1645 Lisp_Object lispy_dummy;
1646 enum scroll_bar_part party_dummy;
1647 Lisp_Object x, y, retval;
1648 int col, row;
1649 unsigned long long_dummy;
1650 struct gcpro gcpro1;
1652 f = SELECTED_FRAME ();
1653 x = y = Qnil;
1655 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1656 /* It's okay for the hook to refrain from storing anything. */
1657 if (FRAME_TERMINAL (f)->mouse_position_hook)
1658 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1659 &lispy_dummy, &party_dummy,
1660 &x, &y,
1661 &long_dummy);
1662 if (! NILP (x))
1664 col = XINT (x);
1665 row = XINT (y);
1666 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1667 XSETINT (x, col);
1668 XSETINT (y, row);
1670 #endif
1671 XSETFRAME (lispy_dummy, f);
1672 retval = Fcons (lispy_dummy, Fcons (x, y));
1673 GCPRO1 (retval);
1674 if (!NILP (Vmouse_position_function))
1675 retval = call1 (Vmouse_position_function, retval);
1676 RETURN_UNGCPRO (retval);
1679 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1680 Smouse_pixel_position, 0, 0, 0,
1681 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1682 The position is given in pixel units, where (0, 0) is the
1683 upper-left corner of the frame, X is the horizontal offset, and Y is
1684 the vertical offset.
1685 If Emacs is running on a mouseless terminal or hasn't been programmed
1686 to read the mouse position, it returns the selected frame for FRAME
1687 and nil for X and Y. */)
1688 (void)
1690 FRAME_PTR f;
1691 Lisp_Object lispy_dummy;
1692 enum scroll_bar_part party_dummy;
1693 Lisp_Object x, y;
1694 unsigned long long_dummy;
1696 f = SELECTED_FRAME ();
1697 x = y = Qnil;
1699 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1700 /* It's okay for the hook to refrain from storing anything. */
1701 if (FRAME_TERMINAL (f)->mouse_position_hook)
1702 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1703 &lispy_dummy, &party_dummy,
1704 &x, &y,
1705 &long_dummy);
1706 #endif
1707 XSETFRAME (lispy_dummy, f);
1708 return Fcons (lispy_dummy, Fcons (x, y));
1711 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1712 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1713 Coordinates are relative to the frame, not a window,
1714 so the coordinates of the top left character in the frame
1715 may be nonzero due to left-hand scroll bars or the menu bar.
1717 The position is given in character cells, where (0, 0) is the
1718 upper-left corner of the frame, X is the horizontal offset, and Y is
1719 the vertical offset.
1721 This function is a no-op for an X frame that is not visible.
1722 If you have just created a frame, you must wait for it to become visible
1723 before calling this function on it, like this.
1724 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1725 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1727 CHECK_LIVE_FRAME (frame);
1728 CHECK_NUMBER (x);
1729 CHECK_NUMBER (y);
1731 /* I think this should be done with a hook. */
1732 #ifdef HAVE_WINDOW_SYSTEM
1733 if (FRAME_WINDOW_P (XFRAME (frame)))
1734 /* Warping the mouse will cause enternotify and focus events. */
1735 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1736 #else
1737 #if defined (MSDOS) && defined (HAVE_MOUSE)
1738 if (FRAME_MSDOS_P (XFRAME (frame)))
1740 Fselect_frame (frame, Qnil);
1741 mouse_moveto (XINT (x), XINT (y));
1743 #else
1744 #ifdef HAVE_GPM
1746 Fselect_frame (frame, Qnil);
1747 term_mouse_moveto (XINT (x), XINT (y));
1749 #endif
1750 #endif
1751 #endif
1753 return Qnil;
1756 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1757 Sset_mouse_pixel_position, 3, 3, 0,
1758 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1759 The position is given in pixels, where (0, 0) is the upper-left corner
1760 of the frame, X is the horizontal offset, and Y is the vertical offset.
1762 Note, this is a no-op for an X frame that is not visible.
1763 If you have just created a frame, you must wait for it to become visible
1764 before calling this function on it, like this.
1765 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1766 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1768 CHECK_LIVE_FRAME (frame);
1769 CHECK_NUMBER (x);
1770 CHECK_NUMBER (y);
1772 /* I think this should be done with a hook. */
1773 #ifdef HAVE_WINDOW_SYSTEM
1774 if (FRAME_WINDOW_P (XFRAME (frame)))
1775 /* Warping the mouse will cause enternotify and focus events. */
1776 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1777 #else
1778 #if defined (MSDOS) && defined (HAVE_MOUSE)
1779 if (FRAME_MSDOS_P (XFRAME (frame)))
1781 Fselect_frame (frame, Qnil);
1782 mouse_moveto (XINT (x), XINT (y));
1784 #else
1785 #ifdef HAVE_GPM
1787 Fselect_frame (frame, Qnil);
1788 term_mouse_moveto (XINT (x), XINT (y));
1790 #endif
1791 #endif
1792 #endif
1794 return Qnil;
1797 static void make_frame_visible_1 (Lisp_Object);
1799 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1800 0, 1, "",
1801 doc: /* Make the frame FRAME visible (assuming it is an X window).
1802 If omitted, FRAME defaults to the currently selected frame. */)
1803 (Lisp_Object frame)
1805 if (NILP (frame))
1806 frame = selected_frame;
1808 CHECK_LIVE_FRAME (frame);
1810 /* I think this should be done with a hook. */
1811 #ifdef HAVE_WINDOW_SYSTEM
1812 if (FRAME_WINDOW_P (XFRAME (frame)))
1814 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1815 x_make_frame_visible (XFRAME (frame));
1817 #endif
1819 make_frame_visible_1 (XFRAME (frame)->root_window);
1821 /* Make menu bar update for the Buffers and Frames menus. */
1822 windows_or_buffers_changed++;
1824 return frame;
1827 /* Update the display_time slot of the buffers shown in WINDOW
1828 and all its descendents. */
1830 static void
1831 make_frame_visible_1 (Lisp_Object window)
1833 struct window *w;
1835 for (;!NILP (window); window = w->next)
1837 w = XWINDOW (window);
1839 if (!NILP (w->buffer))
1840 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1842 if (!NILP (w->vchild))
1843 make_frame_visible_1 (w->vchild);
1844 if (!NILP (w->hchild))
1845 make_frame_visible_1 (w->hchild);
1849 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1850 0, 2, "",
1851 doc: /* Make the frame FRAME invisible.
1852 If omitted, FRAME defaults to the currently selected frame.
1853 On graphical displays, invisible frames are not updated and are
1854 usually not displayed at all, even in a window system's \"taskbar\".
1856 Normally you may not make FRAME invisible if all other frames are invisible,
1857 but if the second optional argument FORCE is non-nil, you may do so.
1859 This function has no effect on text-only terminal frames. Such frames
1860 are always considered visible, whether or not they are currently being
1861 displayed in the terminal. */)
1862 (Lisp_Object frame, Lisp_Object force)
1864 if (NILP (frame))
1865 frame = selected_frame;
1867 CHECK_LIVE_FRAME (frame);
1869 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1870 error ("Attempt to make invisible the sole visible or iconified frame");
1872 #if 0 /* This isn't logically necessary, and it can do GC. */
1873 /* Don't let the frame remain selected. */
1874 if (EQ (frame, selected_frame))
1875 do_switch_frame (next_frame (frame, Qt), 0, 0, Qnil)
1876 #endif
1878 /* Don't allow minibuf_window to remain on a deleted frame. */
1879 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1881 struct frame *sf = XFRAME (selected_frame);
1882 Fset_window_buffer (sf->minibuffer_window,
1883 XWINDOW (minibuf_window)->buffer, Qnil);
1884 minibuf_window = sf->minibuffer_window;
1887 /* I think this should be done with a hook. */
1888 #ifdef HAVE_WINDOW_SYSTEM
1889 if (FRAME_WINDOW_P (XFRAME (frame)))
1890 x_make_frame_invisible (XFRAME (frame));
1891 #endif
1893 /* Make menu bar update for the Buffers and Frames menus. */
1894 windows_or_buffers_changed++;
1896 return Qnil;
1899 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1900 0, 1, "",
1901 doc: /* Make the frame FRAME into an icon.
1902 If omitted, FRAME defaults to the currently selected frame. */)
1903 (Lisp_Object frame)
1905 if (NILP (frame))
1906 frame = selected_frame;
1908 CHECK_LIVE_FRAME (frame);
1910 #if 0 /* This isn't logically necessary, and it can do GC. */
1911 /* Don't let the frame remain selected. */
1912 if (EQ (frame, selected_frame))
1913 Fhandle_switch_frame (next_frame (frame, Qt));
1914 #endif
1916 /* Don't allow minibuf_window to remain on a deleted frame. */
1917 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1919 struct frame *sf = XFRAME (selected_frame);
1920 Fset_window_buffer (sf->minibuffer_window,
1921 XWINDOW (minibuf_window)->buffer, Qnil);
1922 minibuf_window = sf->minibuffer_window;
1925 /* I think this should be done with a hook. */
1926 #ifdef HAVE_WINDOW_SYSTEM
1927 if (FRAME_WINDOW_P (XFRAME (frame)))
1928 x_iconify_frame (XFRAME (frame));
1929 #endif
1931 /* Make menu bar update for the Buffers and Frames menus. */
1932 windows_or_buffers_changed++;
1934 return Qnil;
1937 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1938 1, 1, 0,
1939 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1940 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1941 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1942 On graphical displays, invisible frames are not updated and are
1943 usually not displayed at all, even in a window system's \"taskbar\".
1945 If FRAME is a text-only terminal frame, this always returns t.
1946 Such frames are always considered visible, whether or not they are
1947 currently being displayed on the terminal. */)
1948 (Lisp_Object frame)
1950 CHECK_LIVE_FRAME (frame);
1952 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1954 if (FRAME_VISIBLE_P (XFRAME (frame)))
1955 return Qt;
1956 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1957 return Qicon;
1958 return Qnil;
1961 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1962 0, 0, 0,
1963 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1964 (void)
1966 Lisp_Object tail, frame;
1967 struct frame *f;
1968 Lisp_Object value;
1970 value = Qnil;
1971 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1973 frame = XCAR (tail);
1974 if (!FRAMEP (frame))
1975 continue;
1976 f = XFRAME (frame);
1977 if (FRAME_VISIBLE_P (f))
1978 value = Fcons (frame, value);
1980 return value;
1984 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1985 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1986 If FRAME is invisible or iconified, make it visible.
1987 If you don't specify a frame, the selected frame is used.
1988 If Emacs is displaying on an ordinary terminal or some other device which
1989 doesn't support multiple overlapping frames, this function selects FRAME. */)
1990 (Lisp_Object frame)
1992 struct frame *f;
1993 if (NILP (frame))
1994 frame = selected_frame;
1996 CHECK_LIVE_FRAME (frame);
1998 f = XFRAME (frame);
2000 if (FRAME_TERMCAP_P (f))
2001 /* On a text-only terminal select FRAME. */
2002 Fselect_frame (frame, Qnil);
2003 else
2004 /* Do like the documentation says. */
2005 Fmake_frame_visible (frame);
2007 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2008 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
2010 return Qnil;
2013 /* Should we have a corresponding function called Flower_Power? */
2014 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
2015 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
2016 If you don't specify a frame, the selected frame is used.
2017 If Emacs is displaying on an ordinary terminal or some other device which
2018 doesn't support multiple overlapping frames, this function does nothing. */)
2019 (Lisp_Object frame)
2021 struct frame *f;
2023 if (NILP (frame))
2024 frame = selected_frame;
2026 CHECK_LIVE_FRAME (frame);
2028 f = XFRAME (frame);
2030 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
2031 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
2033 return Qnil;
2037 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
2038 1, 2, 0,
2039 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
2040 In other words, switch-frame events caused by events in FRAME will
2041 request a switch to FOCUS-FRAME, and `last-event-frame' will be
2042 FOCUS-FRAME after reading an event typed at FRAME.
2044 If FOCUS-FRAME is omitted or nil, any existing redirection is
2045 cancelled, and the frame again receives its own keystrokes.
2047 Focus redirection is useful for temporarily redirecting keystrokes to
2048 a surrogate minibuffer frame when a frame doesn't have its own
2049 minibuffer window.
2051 A frame's focus redirection can be changed by `select-frame'. If frame
2052 FOO is selected, and then a different frame BAR is selected, any
2053 frames redirecting their focus to FOO are shifted to redirect their
2054 focus to BAR. This allows focus redirection to work properly when the
2055 user switches from one frame to another using `select-window'.
2057 This means that a frame whose focus is redirected to itself is treated
2058 differently from a frame whose focus is redirected to nil; the former
2059 is affected by `select-frame', while the latter is not.
2061 The redirection lasts until `redirect-frame-focus' is called to change it. */)
2062 (Lisp_Object frame, Lisp_Object focus_frame)
2064 struct frame *f;
2066 /* Note that we don't check for a live frame here. It's reasonable
2067 to redirect the focus of a frame you're about to delete, if you
2068 know what other frame should receive those keystrokes. */
2069 CHECK_FRAME (frame);
2071 if (! NILP (focus_frame))
2072 CHECK_LIVE_FRAME (focus_frame);
2074 f = XFRAME (frame);
2076 f->focus_frame = focus_frame;
2078 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
2079 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
2081 return Qnil;
2085 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
2086 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
2087 This returns nil if FRAME's focus is not redirected.
2088 See `redirect-frame-focus'. */)
2089 (Lisp_Object frame)
2091 CHECK_LIVE_FRAME (frame);
2093 return FRAME_FOCUS_FRAME (XFRAME (frame));
2098 /* Return the value of frame parameter PROP in frame FRAME. */
2100 Lisp_Object
2101 get_frame_param (register struct frame *frame, Lisp_Object prop)
2103 register Lisp_Object tem;
2105 tem = Fassq (prop, frame->param_alist);
2106 if (EQ (tem, Qnil))
2107 return tem;
2108 return Fcdr (tem);
2111 /* Return the buffer-predicate of the selected frame. */
2113 Lisp_Object
2114 frame_buffer_predicate (Lisp_Object frame)
2116 return XFRAME (frame)->buffer_predicate;
2119 /* Return the buffer-list of the selected frame. */
2121 Lisp_Object
2122 frame_buffer_list (Lisp_Object frame)
2124 return XFRAME (frame)->buffer_list;
2127 /* Set the buffer-list of the selected frame. */
2129 void
2130 set_frame_buffer_list (Lisp_Object frame, Lisp_Object list)
2132 XFRAME (frame)->buffer_list = list;
2135 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
2137 void
2138 frames_discard_buffer (Lisp_Object buffer)
2140 Lisp_Object frame, tail;
2142 FOR_EACH_FRAME (tail, frame)
2144 XFRAME (frame)->buffer_list
2145 = Fdelq (buffer, XFRAME (frame)->buffer_list);
2146 XFRAME (frame)->buried_buffer_list
2147 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
2151 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
2152 If the alist already has an element for PROP, we change it. */
2154 void
2155 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
2157 register Lisp_Object tem;
2159 tem = Fassq (prop, *alistptr);
2160 if (EQ (tem, Qnil))
2161 *alistptr = Fcons (Fcons (prop, val), *alistptr);
2162 else
2163 Fsetcdr (tem, val);
2166 static int
2167 frame_name_fnn_p (char *str, EMACS_INT len)
2169 if (len > 1 && str[0] == 'F')
2171 char *end_ptr;
2173 strtol (str + 1, &end_ptr, 10);
2175 if (end_ptr == str + len)
2176 return 1;
2178 return 0;
2181 /* Set the name of the terminal frame. Also used by MSDOS frames.
2182 Modeled after x_set_name which is used for WINDOW frames. */
2184 static void
2185 set_term_frame_name (struct frame *f, Lisp_Object name)
2187 f->explicit_name = ! NILP (name);
2189 /* If NAME is nil, set the name to F<num>. */
2190 if (NILP (name))
2192 char namebuf[20];
2194 /* Check for no change needed in this very common case
2195 before we do any consing. */
2196 if (frame_name_fnn_p (SDATA (f->name),
2197 SBYTES (f->name)))
2198 return;
2200 tty_frame_count++;
2201 sprintf (namebuf, "F%d", tty_frame_count);
2202 name = build_string (namebuf);
2204 else
2206 CHECK_STRING (name);
2208 /* Don't change the name if it's already NAME. */
2209 if (! NILP (Fstring_equal (name, f->name)))
2210 return;
2212 /* Don't allow the user to set the frame name to F<num>, so it
2213 doesn't clash with the names we generate for terminal frames. */
2214 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2215 error ("Frame names of the form F<num> are usurped by Emacs");
2218 f->name = name;
2219 update_mode_lines = 1;
2222 void
2223 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2225 register Lisp_Object old_alist_elt;
2227 /* The buffer-list parameters are stored in a special place and not
2228 in the alist. */
2229 if (EQ (prop, Qbuffer_list))
2231 f->buffer_list = val;
2232 return;
2234 if (EQ (prop, Qburied_buffer_list))
2236 f->buried_buffer_list = val;
2237 return;
2240 /* If PROP is a symbol which is supposed to have frame-local values,
2241 and it is set up based on this frame, switch to the global
2242 binding. That way, we can create or alter the frame-local binding
2243 without messing up the symbol's status. */
2244 if (SYMBOLP (prop))
2246 struct Lisp_Symbol *sym = XSYMBOL (prop);
2247 start:
2248 switch (sym->redirect)
2250 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2251 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2252 case SYMBOL_LOCALIZED:
2253 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2254 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2255 swap_in_global_binding (sym);
2256 break;
2258 default: abort ();
2262 /* The tty color needed to be set before the frame's parameter
2263 alist was updated with the new value. This is not true any more,
2264 but we still do this test early on. */
2265 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2266 && f == FRAME_TTY (f)->previous_frame)
2267 /* Force redisplay of this tty. */
2268 FRAME_TTY (f)->previous_frame = NULL;
2270 /* Update the frame parameter alist. */
2271 old_alist_elt = Fassq (prop, f->param_alist);
2272 if (EQ (old_alist_elt, Qnil))
2273 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2274 else
2275 Fsetcdr (old_alist_elt, val);
2277 /* Update some other special parameters in their special places
2278 in addition to the alist. */
2280 if (EQ (prop, Qbuffer_predicate))
2281 f->buffer_predicate = val;
2283 if (! FRAME_WINDOW_P (f))
2285 if (EQ (prop, Qmenu_bar_lines))
2286 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2287 else if (EQ (prop, Qname))
2288 set_term_frame_name (f, val);
2291 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2293 if (! MINI_WINDOW_P (XWINDOW (val)))
2294 error ("Surrogate minibuffer windows must be minibuffer windows");
2296 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2297 && !EQ (val, f->minibuffer_window))
2298 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2300 /* Install the chosen minibuffer window, with proper buffer. */
2301 f->minibuffer_window = val;
2305 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2306 doc: /* Return the parameters-alist of frame FRAME.
2307 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2308 The meaningful PARMs depend on the kind of frame.
2309 If FRAME is omitted, return information on the currently selected frame. */)
2310 (Lisp_Object frame)
2312 Lisp_Object alist;
2313 FRAME_PTR f;
2314 int height, width;
2315 struct gcpro gcpro1;
2317 if (NILP (frame))
2318 frame = selected_frame;
2320 CHECK_FRAME (frame);
2321 f = XFRAME (frame);
2323 if (!FRAME_LIVE_P (f))
2324 return Qnil;
2326 alist = Fcopy_alist (f->param_alist);
2327 GCPRO1 (alist);
2329 if (!FRAME_WINDOW_P (f))
2331 int fg = FRAME_FOREGROUND_PIXEL (f);
2332 int bg = FRAME_BACKGROUND_PIXEL (f);
2333 Lisp_Object elt;
2335 /* If the frame's parameter alist says the colors are
2336 unspecified and reversed, take the frame's background pixel
2337 for foreground and vice versa. */
2338 elt = Fassq (Qforeground_color, alist);
2339 if (CONSP (elt) && STRINGP (XCDR (elt)))
2341 if (strncmp (SDATA (XCDR (elt)),
2342 unspecified_bg,
2343 SCHARS (XCDR (elt))) == 0)
2344 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2345 else if (strncmp (SDATA (XCDR (elt)),
2346 unspecified_fg,
2347 SCHARS (XCDR (elt))) == 0)
2348 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2350 else
2351 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2352 elt = Fassq (Qbackground_color, alist);
2353 if (CONSP (elt) && STRINGP (XCDR (elt)))
2355 if (strncmp (SDATA (XCDR (elt)),
2356 unspecified_fg,
2357 SCHARS (XCDR (elt))) == 0)
2358 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2359 else if (strncmp (SDATA (XCDR (elt)),
2360 unspecified_bg,
2361 SCHARS (XCDR (elt))) == 0)
2362 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2364 else
2365 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2366 store_in_alist (&alist, intern ("font"),
2367 build_string (FRAME_MSDOS_P (f)
2368 ? "ms-dos"
2369 : FRAME_W32_P (f) ? "w32term"
2370 :"tty"));
2372 store_in_alist (&alist, Qname, f->name);
2373 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2374 store_in_alist (&alist, Qheight, make_number (height));
2375 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2376 store_in_alist (&alist, Qwidth, make_number (width));
2377 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2378 store_in_alist (&alist, Qminibuffer,
2379 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2380 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2381 : FRAME_MINIBUF_WINDOW (f)));
2382 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2383 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2384 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2386 /* I think this should be done with a hook. */
2387 #ifdef HAVE_WINDOW_SYSTEM
2388 if (FRAME_WINDOW_P (f))
2389 x_report_frame_params (f, &alist);
2390 else
2391 #endif
2393 /* This ought to be correct in f->param_alist for an X frame. */
2394 Lisp_Object lines;
2395 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2396 store_in_alist (&alist, Qmenu_bar_lines, lines);
2399 UNGCPRO;
2400 return alist;
2404 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2405 doc: /* Return FRAME's value for parameter PARAMETER.
2406 If FRAME is nil, describe the currently selected frame. */)
2407 (Lisp_Object frame, Lisp_Object parameter)
2409 struct frame *f;
2410 Lisp_Object value;
2412 if (NILP (frame))
2413 frame = selected_frame;
2414 else
2415 CHECK_FRAME (frame);
2416 CHECK_SYMBOL (parameter);
2418 f = XFRAME (frame);
2419 value = Qnil;
2421 if (FRAME_LIVE_P (f))
2423 /* Avoid consing in frequent cases. */
2424 if (EQ (parameter, Qname))
2425 value = f->name;
2426 #ifdef HAVE_X_WINDOWS
2427 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2428 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2429 #endif /* HAVE_X_WINDOWS */
2430 else if (EQ (parameter, Qbackground_color)
2431 || EQ (parameter, Qforeground_color))
2433 value = Fassq (parameter, f->param_alist);
2434 if (CONSP (value))
2436 value = XCDR (value);
2437 /* Fframe_parameters puts the actual fg/bg color names,
2438 even if f->param_alist says otherwise. This is
2439 important when param_alist's notion of colors is
2440 "unspecified". We need to do the same here. */
2441 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2443 const char *color_name;
2444 EMACS_INT csz;
2446 if (EQ (parameter, Qbackground_color))
2448 color_name = SDATA (value);
2449 csz = SCHARS (value);
2450 if (strncmp (color_name, unspecified_bg, csz) == 0)
2451 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2452 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2453 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2455 else if (EQ (parameter, Qforeground_color))
2457 color_name = SDATA (value);
2458 csz = SCHARS (value);
2459 if (strncmp (color_name, unspecified_fg, csz) == 0)
2460 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2461 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2462 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2466 else
2467 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2469 else if (EQ (parameter, Qdisplay_type)
2470 || EQ (parameter, Qbackground_mode))
2471 value = Fcdr (Fassq (parameter, f->param_alist));
2472 else
2473 /* FIXME: Avoid this code path at all (as well as code duplication)
2474 by sharing more code with Fframe_parameters. */
2475 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2478 return value;
2482 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2483 Smodify_frame_parameters, 2, 2, 0,
2484 doc: /* Modify the parameters of frame FRAME according to ALIST.
2485 If FRAME is nil, it defaults to the selected frame.
2486 ALIST is an alist of parameters to change and their new values.
2487 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2488 The meaningful PARMs depend on the kind of frame.
2489 Undefined PARMs are ignored, but stored in the frame's parameter list
2490 so that `frame-parameters' will return them.
2492 The value of frame parameter FOO can also be accessed
2493 as a frame-local binding for the variable FOO, if you have
2494 enabled such bindings for that variable with `make-variable-frame-local'.
2495 Note that this functionality is obsolete as of Emacs 22.2, and its
2496 use is not recommended. Explicitly check for a frame-parameter instead. */)
2497 (Lisp_Object frame, Lisp_Object alist)
2499 FRAME_PTR f;
2500 register Lisp_Object tail, prop, val;
2502 if (EQ (frame, Qnil))
2503 frame = selected_frame;
2504 CHECK_LIVE_FRAME (frame);
2505 f = XFRAME (frame);
2507 /* I think this should be done with a hook. */
2508 #ifdef HAVE_WINDOW_SYSTEM
2509 if (FRAME_WINDOW_P (f))
2510 x_set_frame_parameters (f, alist);
2511 else
2512 #endif
2513 #ifdef MSDOS
2514 if (FRAME_MSDOS_P (f))
2515 IT_set_frame_parameters (f, alist);
2516 else
2517 #endif
2520 int length = XINT (Flength (alist));
2521 int i;
2522 Lisp_Object *parms
2523 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2524 Lisp_Object *values
2525 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2527 /* Extract parm names and values into those vectors. */
2529 i = 0;
2530 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2532 Lisp_Object elt;
2534 elt = XCAR (tail);
2535 parms[i] = Fcar (elt);
2536 values[i] = Fcdr (elt);
2537 i++;
2540 /* Now process them in reverse of specified order. */
2541 for (i--; i >= 0; i--)
2543 prop = parms[i];
2544 val = values[i];
2545 store_frame_param (f, prop, val);
2547 /* Changing the background color might change the background
2548 mode, so that we have to load new defface specs.
2549 Call frame-set-background-mode to do that. */
2550 if (EQ (prop, Qbackground_color))
2551 call1 (Qframe_set_background_mode, frame);
2554 return Qnil;
2557 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2558 0, 1, 0,
2559 doc: /* Height in pixels of a line in the font in frame FRAME.
2560 If FRAME is omitted, the selected frame is used.
2561 For a terminal frame, the value is always 1. */)
2562 (Lisp_Object frame)
2564 struct frame *f;
2566 if (NILP (frame))
2567 frame = selected_frame;
2568 CHECK_FRAME (frame);
2569 f = XFRAME (frame);
2571 #ifdef HAVE_WINDOW_SYSTEM
2572 if (FRAME_WINDOW_P (f))
2573 return make_number (x_char_height (f));
2574 else
2575 #endif
2576 return make_number (1);
2580 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2581 0, 1, 0,
2582 doc: /* Width in pixels of characters in the font in frame FRAME.
2583 If FRAME is omitted, the selected frame is used.
2584 On a graphical screen, the width is the standard width of the default font.
2585 For a terminal screen, the value is always 1. */)
2586 (Lisp_Object frame)
2588 struct frame *f;
2590 if (NILP (frame))
2591 frame = selected_frame;
2592 CHECK_FRAME (frame);
2593 f = XFRAME (frame);
2595 #ifdef HAVE_WINDOW_SYSTEM
2596 if (FRAME_WINDOW_P (f))
2597 return make_number (x_char_width (f));
2598 else
2599 #endif
2600 return make_number (1);
2603 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2604 Sframe_pixel_height, 0, 1, 0,
2605 doc: /* Return a FRAME's height in pixels.
2606 If FRAME is omitted, the selected frame is used. The exact value
2607 of the result depends on the window-system and toolkit in use:
2609 In the Gtk+ version of Emacs, it includes only any window (including
2610 the minibuffer or eacho area), mode line, and header line. It does not
2611 include the tool bar or menu bar.
2613 With the Motif or Lucid toolkits, it also includes the tool bar (but
2614 not the menu bar).
2616 In a graphical version with no toolkit, it includes both the tool bar
2617 and menu bar.
2619 For a text-only terminal, it includes the menu bar. In this case, the
2620 result is really in characters rather than pixels (i.e., is identical
2621 to `frame-height'). */)
2622 (Lisp_Object frame)
2624 struct frame *f;
2626 if (NILP (frame))
2627 frame = selected_frame;
2628 CHECK_FRAME (frame);
2629 f = XFRAME (frame);
2631 #ifdef HAVE_WINDOW_SYSTEM
2632 if (FRAME_WINDOW_P (f))
2633 return make_number (x_pixel_height (f));
2634 else
2635 #endif
2636 return make_number (FRAME_LINES (f));
2639 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2640 Sframe_pixel_width, 0, 1, 0,
2641 doc: /* Return FRAME's width in pixels.
2642 For a terminal frame, the result really gives the width in characters.
2643 If FRAME is omitted, the selected frame is used. */)
2644 (Lisp_Object frame)
2646 struct frame *f;
2648 if (NILP (frame))
2649 frame = selected_frame;
2650 CHECK_FRAME (frame);
2651 f = XFRAME (frame);
2653 #ifdef HAVE_WINDOW_SYSTEM
2654 if (FRAME_WINDOW_P (f))
2655 return make_number (x_pixel_width (f));
2656 else
2657 #endif
2658 return make_number (FRAME_COLS (f));
2661 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2662 doc: /* Specify that the frame FRAME has LINES lines.
2663 Optional third arg non-nil means that redisplay should use LINES lines
2664 but that the idea of the actual height of the frame should not be changed. */)
2665 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2667 register struct frame *f;
2669 CHECK_NUMBER (lines);
2670 if (NILP (frame))
2671 frame = selected_frame;
2672 CHECK_LIVE_FRAME (frame);
2673 f = XFRAME (frame);
2675 /* I think this should be done with a hook. */
2676 #ifdef HAVE_WINDOW_SYSTEM
2677 if (FRAME_WINDOW_P (f))
2679 if (XINT (lines) != FRAME_LINES (f))
2680 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2681 do_pending_window_change (0);
2683 else
2684 #endif
2685 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2686 return Qnil;
2689 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2690 doc: /* Specify that the frame FRAME has COLS columns.
2691 Optional third arg non-nil means that redisplay should use COLS columns
2692 but that the idea of the actual width of the frame should not be changed. */)
2693 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2695 register struct frame *f;
2696 CHECK_NUMBER (cols);
2697 if (NILP (frame))
2698 frame = selected_frame;
2699 CHECK_LIVE_FRAME (frame);
2700 f = XFRAME (frame);
2702 /* I think this should be done with a hook. */
2703 #ifdef HAVE_WINDOW_SYSTEM
2704 if (FRAME_WINDOW_P (f))
2706 if (XINT (cols) != FRAME_COLS (f))
2707 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2708 do_pending_window_change (0);
2710 else
2711 #endif
2712 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2713 return Qnil;
2716 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2717 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2718 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2720 register struct frame *f;
2722 CHECK_LIVE_FRAME (frame);
2723 CHECK_NUMBER (cols);
2724 CHECK_NUMBER (rows);
2725 f = XFRAME (frame);
2727 /* I think this should be done with a hook. */
2728 #ifdef HAVE_WINDOW_SYSTEM
2729 if (FRAME_WINDOW_P (f))
2731 if (XINT (rows) != FRAME_LINES (f)
2732 || XINT (cols) != FRAME_COLS (f)
2733 || f->new_text_lines || f->new_text_cols)
2734 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2735 do_pending_window_change (0);
2737 else
2738 #endif
2739 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2741 return Qnil;
2744 DEFUN ("set-frame-position", Fset_frame_position,
2745 Sset_frame_position, 3, 3, 0,
2746 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2747 This is actually the position of the upper left corner of the frame.
2748 Negative values for XOFFSET or YOFFSET are interpreted relative to
2749 the rightmost or bottommost possible position (that stays within the screen). */)
2750 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2752 register struct frame *f;
2754 CHECK_LIVE_FRAME (frame);
2755 CHECK_NUMBER (xoffset);
2756 CHECK_NUMBER (yoffset);
2757 f = XFRAME (frame);
2759 /* I think this should be done with a hook. */
2760 #ifdef HAVE_WINDOW_SYSTEM
2761 if (FRAME_WINDOW_P (f))
2762 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2763 #endif
2765 return Qt;
2769 /***********************************************************************
2770 Frame Parameters
2771 ***********************************************************************/
2773 /* Connect the frame-parameter names for X frames
2774 to the ways of passing the parameter values to the window system.
2776 The name of a parameter, as a Lisp symbol,
2777 has an `x-frame-parameter' property which is an integer in Lisp
2778 that is an index in this table. */
2780 struct frame_parm_table {
2781 char *name;
2782 Lisp_Object *variable;
2785 static struct frame_parm_table frame_parms[] =
2787 {"auto-raise", &Qauto_raise},
2788 {"auto-lower", &Qauto_lower},
2789 {"background-color", 0},
2790 {"border-color", &Qborder_color},
2791 {"border-width", &Qborder_width},
2792 {"cursor-color", &Qcursor_color},
2793 {"cursor-type", &Qcursor_type},
2794 {"font", 0},
2795 {"foreground-color", 0},
2796 {"icon-name", &Qicon_name},
2797 {"icon-type", &Qicon_type},
2798 {"internal-border-width", &Qinternal_border_width},
2799 {"menu-bar-lines", &Qmenu_bar_lines},
2800 {"mouse-color", &Qmouse_color},
2801 {"name", &Qname},
2802 {"scroll-bar-width", &Qscroll_bar_width},
2803 {"title", &Qtitle},
2804 {"unsplittable", &Qunsplittable},
2805 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2806 {"visibility", &Qvisibility},
2807 {"tool-bar-lines", &Qtool_bar_lines},
2808 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2809 {"scroll-bar-background", &Qscroll_bar_background},
2810 {"screen-gamma", &Qscreen_gamma},
2811 {"line-spacing", &Qline_spacing},
2812 {"left-fringe", &Qleft_fringe},
2813 {"right-fringe", &Qright_fringe},
2814 {"wait-for-wm", &Qwait_for_wm},
2815 {"fullscreen", &Qfullscreen},
2816 {"font-backend", &Qfont_backend},
2817 {"alpha", &Qalpha},
2818 {"sticky", &Qsticky},
2821 #ifdef HAVE_WINDOW_SYSTEM
2823 extern Lisp_Object Qbox;
2824 extern Lisp_Object Qtop;
2826 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2827 wanted positions of the WM window (not Emacs window).
2828 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2829 window (FRAME_X_WINDOW).
2832 void
2833 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2835 int newwidth = FRAME_COLS (f);
2836 int newheight = FRAME_LINES (f);
2837 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2839 *top_pos = f->top_pos;
2840 *left_pos = f->left_pos;
2842 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2844 int ph;
2846 ph = x_display_pixel_height (dpyinfo);
2847 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2848 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2849 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2850 *top_pos = 0;
2853 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2855 int pw;
2857 pw = x_display_pixel_width (dpyinfo);
2858 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2859 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2860 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2861 *left_pos = 0;
2864 *width = newwidth;
2865 *height = newheight;
2869 /* Change the parameters of frame F as specified by ALIST.
2870 If a parameter is not specially recognized, do nothing special;
2871 otherwise call the `x_set_...' function for that parameter.
2872 Except for certain geometry properties, always call store_frame_param
2873 to store the new value in the parameter alist. */
2875 void
2876 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2878 Lisp_Object tail;
2880 /* If both of these parameters are present, it's more efficient to
2881 set them both at once. So we wait until we've looked at the
2882 entire list before we set them. */
2883 int width, height;
2885 /* Same here. */
2886 Lisp_Object left, top;
2888 /* Same with these. */
2889 Lisp_Object icon_left, icon_top;
2891 /* Record in these vectors all the parms specified. */
2892 Lisp_Object *parms;
2893 Lisp_Object *values;
2894 int i, p;
2895 int left_no_change = 0, top_no_change = 0;
2896 int icon_left_no_change = 0, icon_top_no_change = 0;
2897 int size_changed = 0;
2898 struct gcpro gcpro1, gcpro2;
2900 i = 0;
2901 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2902 i++;
2904 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2905 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2907 /* Extract parm names and values into those vectors. */
2909 i = 0;
2910 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2912 Lisp_Object elt;
2914 elt = XCAR (tail);
2915 parms[i] = Fcar (elt);
2916 values[i] = Fcdr (elt);
2917 i++;
2919 /* TAIL and ALIST are not used again below here. */
2920 alist = tail = Qnil;
2922 GCPRO2 (*parms, *values);
2923 gcpro1.nvars = i;
2924 gcpro2.nvars = i;
2926 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2927 because their values appear in VALUES and strings are not valid. */
2928 top = left = Qunbound;
2929 icon_left = icon_top = Qunbound;
2931 /* Provide default values for HEIGHT and WIDTH. */
2932 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2933 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2935 /* Process foreground_color and background_color before anything else.
2936 They are independent of other properties, but other properties (e.g.,
2937 cursor_color) are dependent upon them. */
2938 /* Process default font as well, since fringe widths depends on it. */
2939 for (p = 0; p < i; p++)
2941 Lisp_Object prop, val;
2943 prop = parms[p];
2944 val = values[p];
2945 if (EQ (prop, Qforeground_color)
2946 || EQ (prop, Qbackground_color)
2947 || EQ (prop, Qfont))
2949 register Lisp_Object param_index, old_value;
2951 old_value = get_frame_param (f, prop);
2952 if (NILP (Fequal (val, old_value)))
2954 store_frame_param (f, prop, val);
2956 param_index = Fget (prop, Qx_frame_parameter);
2957 if (NATNUMP (param_index)
2958 && (XFASTINT (param_index)
2959 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2960 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2961 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2966 /* Now process them in reverse of specified order. */
2967 for (i--; i >= 0; i--)
2969 Lisp_Object prop, val;
2971 prop = parms[i];
2972 val = values[i];
2974 if (EQ (prop, Qwidth) && NATNUMP (val))
2976 size_changed = 1;
2977 width = XFASTINT (val);
2979 else if (EQ (prop, Qheight) && NATNUMP (val))
2981 size_changed = 1;
2982 height = XFASTINT (val);
2984 else if (EQ (prop, Qtop))
2985 top = val;
2986 else if (EQ (prop, Qleft))
2987 left = val;
2988 else if (EQ (prop, Qicon_top))
2989 icon_top = val;
2990 else if (EQ (prop, Qicon_left))
2991 icon_left = val;
2992 else if (EQ (prop, Qforeground_color)
2993 || EQ (prop, Qbackground_color)
2994 || EQ (prop, Qfont))
2995 /* Processed above. */
2996 continue;
2997 else
2999 register Lisp_Object param_index, old_value;
3001 old_value = get_frame_param (f, prop);
3003 store_frame_param (f, prop, val);
3005 param_index = Fget (prop, Qx_frame_parameter);
3006 if (NATNUMP (param_index)
3007 && (XFASTINT (param_index)
3008 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3009 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
3010 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
3014 /* Don't die if just one of these was set. */
3015 if (EQ (left, Qunbound))
3017 left_no_change = 1;
3018 if (f->left_pos < 0)
3019 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
3020 else
3021 XSETINT (left, f->left_pos);
3023 if (EQ (top, Qunbound))
3025 top_no_change = 1;
3026 if (f->top_pos < 0)
3027 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
3028 else
3029 XSETINT (top, f->top_pos);
3032 /* If one of the icon positions was not set, preserve or default it. */
3033 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
3035 icon_left_no_change = 1;
3036 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
3037 if (NILP (icon_left))
3038 XSETINT (icon_left, 0);
3040 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
3042 icon_top_no_change = 1;
3043 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
3044 if (NILP (icon_top))
3045 XSETINT (icon_top, 0);
3048 /* Don't set these parameters unless they've been explicitly
3049 specified. The window might be mapped or resized while we're in
3050 this function, and we don't want to override that unless the lisp
3051 code has asked for it.
3053 Don't set these parameters unless they actually differ from the
3054 window's current parameters; the window may not actually exist
3055 yet. */
3057 Lisp_Object frame;
3059 check_frame_size (f, &height, &width);
3061 XSETFRAME (frame, f);
3063 if (size_changed
3064 && (width != FRAME_COLS (f)
3065 || height != FRAME_LINES (f)
3066 || f->new_text_lines || f->new_text_cols))
3067 Fset_frame_size (frame, make_number (width), make_number (height));
3069 if ((!NILP (left) || !NILP (top))
3070 && ! (left_no_change && top_no_change)
3071 && ! (NUMBERP (left) && XINT (left) == f->left_pos
3072 && NUMBERP (top) && XINT (top) == f->top_pos))
3074 int leftpos = 0;
3075 int toppos = 0;
3077 /* Record the signs. */
3078 f->size_hint_flags &= ~ (XNegative | YNegative);
3079 if (EQ (left, Qminus))
3080 f->size_hint_flags |= XNegative;
3081 else if (INTEGERP (left))
3083 leftpos = XINT (left);
3084 if (leftpos < 0)
3085 f->size_hint_flags |= XNegative;
3087 else if (CONSP (left) && EQ (XCAR (left), Qminus)
3088 && CONSP (XCDR (left))
3089 && INTEGERP (XCAR (XCDR (left))))
3091 leftpos = - XINT (XCAR (XCDR (left)));
3092 f->size_hint_flags |= XNegative;
3094 else if (CONSP (left) && EQ (XCAR (left), Qplus)
3095 && CONSP (XCDR (left))
3096 && INTEGERP (XCAR (XCDR (left))))
3098 leftpos = XINT (XCAR (XCDR (left)));
3101 if (EQ (top, Qminus))
3102 f->size_hint_flags |= YNegative;
3103 else if (INTEGERP (top))
3105 toppos = XINT (top);
3106 if (toppos < 0)
3107 f->size_hint_flags |= YNegative;
3109 else if (CONSP (top) && EQ (XCAR (top), Qminus)
3110 && CONSP (XCDR (top))
3111 && INTEGERP (XCAR (XCDR (top))))
3113 toppos = - XINT (XCAR (XCDR (top)));
3114 f->size_hint_flags |= YNegative;
3116 else if (CONSP (top) && EQ (XCAR (top), Qplus)
3117 && CONSP (XCDR (top))
3118 && INTEGERP (XCAR (XCDR (top))))
3120 toppos = XINT (XCAR (XCDR (top)));
3124 /* Store the numeric value of the position. */
3125 f->top_pos = toppos;
3126 f->left_pos = leftpos;
3128 f->win_gravity = NorthWestGravity;
3130 /* Actually set that position, and convert to absolute. */
3131 x_set_offset (f, leftpos, toppos, -1);
3134 if ((!NILP (icon_left) || !NILP (icon_top))
3135 && ! (icon_left_no_change && icon_top_no_change))
3136 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
3139 UNGCPRO;
3143 /* Insert a description of internally-recorded parameters of frame X
3144 into the parameter alist *ALISTPTR that is to be given to the user.
3145 Only parameters that are specific to the X window system
3146 and whose values are not correctly recorded in the frame's
3147 param_alist need to be considered here. */
3149 void
3150 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3152 char buf[16];
3153 Lisp_Object tem;
3155 /* Represent negative positions (off the top or left screen edge)
3156 in a way that Fmodify_frame_parameters will understand correctly. */
3157 XSETINT (tem, f->left_pos);
3158 if (f->left_pos >= 0)
3159 store_in_alist (alistptr, Qleft, tem);
3160 else
3161 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3163 XSETINT (tem, f->top_pos);
3164 if (f->top_pos >= 0)
3165 store_in_alist (alistptr, Qtop, tem);
3166 else
3167 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3169 store_in_alist (alistptr, Qborder_width,
3170 make_number (f->border_width));
3171 store_in_alist (alistptr, Qinternal_border_width,
3172 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3173 store_in_alist (alistptr, Qleft_fringe,
3174 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3175 store_in_alist (alistptr, Qright_fringe,
3176 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3177 store_in_alist (alistptr, Qscroll_bar_width,
3178 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3179 ? make_number (0)
3180 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3181 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3182 /* nil means "use default width"
3183 for non-toolkit scroll bar.
3184 ruler-mode.el depends on this. */
3185 : Qnil));
3186 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
3187 store_in_alist (alistptr, Qwindow_id,
3188 build_string (buf));
3189 #ifdef HAVE_X_WINDOWS
3190 #ifdef USE_X_TOOLKIT
3191 /* Tooltip frame may not have this widget. */
3192 if (FRAME_X_OUTPUT (f)->widget)
3193 #endif
3194 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
3195 store_in_alist (alistptr, Qouter_window_id,
3196 build_string (buf));
3197 #endif
3198 store_in_alist (alistptr, Qicon_name, f->icon_name);
3199 FRAME_SAMPLE_VISIBILITY (f);
3200 store_in_alist (alistptr, Qvisibility,
3201 (FRAME_VISIBLE_P (f) ? Qt
3202 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3203 store_in_alist (alistptr, Qdisplay,
3204 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3206 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3207 tem = Qnil;
3208 else
3209 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3210 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3211 store_in_alist (alistptr, Qparent_id, tem);
3215 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3216 the previous value of that parameter, NEW_VALUE is the new value. */
3218 void
3219 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3221 if (NILP (new_value))
3222 f->want_fullscreen = FULLSCREEN_NONE;
3223 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3224 f->want_fullscreen = FULLSCREEN_BOTH;
3225 else if (EQ (new_value, Qfullwidth))
3226 f->want_fullscreen = FULLSCREEN_WIDTH;
3227 else if (EQ (new_value, Qfullheight))
3228 f->want_fullscreen = FULLSCREEN_HEIGHT;
3229 else if (EQ (new_value, Qmaximized))
3230 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3232 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3233 FRAME_TERMINAL (f)->fullscreen_hook (f);
3237 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3238 the previous value of that parameter, NEW_VALUE is the new value. */
3240 void
3241 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3243 if (NILP (new_value))
3244 f->extra_line_spacing = 0;
3245 else if (NATNUMP (new_value))
3246 f->extra_line_spacing = XFASTINT (new_value);
3247 else
3248 signal_error ("Invalid line-spacing", new_value);
3249 if (FRAME_VISIBLE_P (f))
3250 redraw_frame (f);
3254 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3255 the previous value of that parameter, NEW_VALUE is the new value. */
3257 void
3258 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3260 Lisp_Object bgcolor;
3262 if (NILP (new_value))
3263 f->gamma = 0;
3264 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3265 /* The value 0.4545 is the normal viewing gamma. */
3266 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3267 else
3268 signal_error ("Invalid screen-gamma", new_value);
3270 /* Apply the new gamma value to the frame background. */
3271 bgcolor = Fassq (Qbackground_color, f->param_alist);
3272 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3274 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3275 if (NATNUMP (index)
3276 && (XFASTINT (index)
3277 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3278 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3279 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (index)])
3280 (f, bgcolor, Qnil);
3283 Fclear_face_cache (Qnil);
3287 void
3288 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3290 Lisp_Object frame, font_object, font_param = Qnil;
3291 int fontset = -1;
3293 /* Set the frame parameter back to the old value because we may
3294 fail to use ARG as the new parameter value. */
3295 store_frame_param (f, Qfont, oldval);
3297 /* ARG is a fontset name, a font name, a cons of fontset name and a
3298 font object, or a font object. In the last case, this function
3299 never fail. */
3300 if (STRINGP (arg))
3302 font_param = arg;
3303 fontset = fs_query_fontset (arg, 0);
3304 if (fontset < 0)
3306 font_object = font_open_by_name (f, SDATA (arg));
3307 if (NILP (font_object))
3308 error ("Font `%s' is not defined", SDATA (arg));
3309 arg = AREF (font_object, FONT_NAME_INDEX);
3311 else if (fontset > 0)
3313 Lisp_Object ascii_font = fontset_ascii (fontset);
3315 font_object = font_open_by_name (f, SDATA (ascii_font));
3316 if (NILP (font_object))
3317 error ("Font `%s' is not defined", SDATA (arg));
3318 arg = AREF (font_object, FONT_NAME_INDEX);
3320 else
3321 error ("The default fontset can't be used for a frame font");
3323 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3325 /* This is the case that the ASCII font of F's fontset XCAR
3326 (arg) is changed to the font XCDR (arg) by
3327 `set-fontset-font'. */
3328 fontset = fs_query_fontset (XCAR (arg), 0);
3329 if (fontset < 0)
3330 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3331 font_object = XCDR (arg);
3332 arg = AREF (font_object, FONT_NAME_INDEX);
3333 font_param = Ffont_get (font_object, QCname);
3335 else if (FONT_OBJECT_P (arg))
3337 font_object = arg;
3338 font_param = Ffont_get (font_object, QCname);
3339 /* This is to store the XLFD font name in the frame parameter for
3340 backward compatibility. We should store the font-object
3341 itself in the future. */
3342 arg = AREF (font_object, FONT_NAME_INDEX);
3343 fontset = FRAME_FONTSET (f);
3344 /* Check if we can use the current fontset. If not, set FONTSET
3345 to -1 to generate a new fontset from FONT-OBJECT. */
3346 if (fontset >= 0)
3348 Lisp_Object ascii_font = fontset_ascii (fontset);
3349 Lisp_Object spec = font_spec_from_name (ascii_font);
3351 if (! font_match_p (spec, font_object))
3352 fontset = -1;
3355 else
3356 signal_error ("Invalid font", arg);
3358 if (! NILP (Fequal (font_object, oldval)))
3359 return;
3361 x_new_font (f, font_object, fontset);
3362 store_frame_param (f, Qfont, arg);
3363 #ifdef HAVE_X_WINDOWS
3364 store_frame_param (f, Qfont_param, font_param);
3365 #endif
3366 /* Recalculate toolbar height. */
3367 f->n_tool_bar_rows = 0;
3368 /* Ensure we redraw it. */
3369 clear_current_matrices (f);
3371 recompute_basic_faces (f);
3373 do_pending_window_change (0);
3375 /* We used to call face-set-after-frame-default here, but it leads to
3376 recursive calls (since that function can set the `default' face's
3377 font which in turns changes the frame's `font' parameter).
3378 Also I don't know what this call is meant to do, but it seems the
3379 wrong way to do it anyway (it does a lot more work than what seems
3380 reasonable in response to a change to `font'). */
3384 void
3385 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3387 if (! NILP (new_value)
3388 && !CONSP (new_value))
3390 char *p0, *p1;
3392 CHECK_STRING (new_value);
3393 p0 = p1 = SDATA (new_value);
3394 new_value = Qnil;
3395 while (*p0)
3397 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3398 if (p0 < p1)
3399 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3400 new_value);
3401 if (*p1)
3403 int c;
3405 while ((c = *++p1) && isspace (c));
3407 p0 = p1;
3409 new_value = Fnreverse (new_value);
3412 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3413 return;
3415 if (FRAME_FONT (f))
3416 free_all_realized_faces (Qnil);
3418 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3419 if (NILP (new_value))
3421 if (NILP (old_value))
3422 error ("No font backend available");
3423 font_update_drivers (f, old_value);
3424 error ("None of specified font backends are available");
3426 store_frame_param (f, Qfont_backend, new_value);
3428 if (FRAME_FONT (f))
3430 Lisp_Object frame;
3432 XSETFRAME (frame, f);
3433 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3434 ++face_change_count;
3435 ++windows_or_buffers_changed;
3440 void
3441 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3443 compute_fringe_widths (f, 1);
3446 void
3447 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3449 CHECK_NUMBER (arg);
3451 if (XINT (arg) == f->border_width)
3452 return;
3454 if (FRAME_X_WINDOW (f) != 0)
3455 error ("Cannot change the border width of a frame");
3457 f->border_width = XINT (arg);
3460 void
3461 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3463 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3465 CHECK_NUMBER (arg);
3466 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3467 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3468 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3470 #ifdef USE_X_TOOLKIT
3471 if (FRAME_X_OUTPUT (f)->edit_widget)
3472 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3473 #endif
3475 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3476 return;
3478 if (FRAME_X_WINDOW (f) != 0)
3480 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3481 SET_FRAME_GARBAGED (f);
3482 do_pending_window_change (0);
3484 else
3485 SET_FRAME_GARBAGED (f);
3488 void
3489 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3491 Lisp_Object frame;
3492 XSETFRAME (frame, f);
3494 if (NILP (value))
3495 Fmake_frame_invisible (frame, Qt);
3496 else if (EQ (value, Qicon))
3497 Ficonify_frame (frame);
3498 else
3499 Fmake_frame_visible (frame);
3502 void
3503 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3505 f->auto_raise = !EQ (Qnil, arg);
3508 void
3509 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3511 f->auto_lower = !EQ (Qnil, arg);
3514 void
3515 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3517 f->no_split = !NILP (arg);
3520 void
3521 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3523 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3524 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3525 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3526 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3528 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3529 = (NILP (arg)
3530 ? vertical_scroll_bar_none
3531 : EQ (Qleft, arg)
3532 ? vertical_scroll_bar_left
3533 : EQ (Qright, arg)
3534 ? vertical_scroll_bar_right
3535 : EQ (Qleft, Vdefault_frame_scroll_bars)
3536 ? vertical_scroll_bar_left
3537 : EQ (Qright, Vdefault_frame_scroll_bars)
3538 ? vertical_scroll_bar_right
3539 : vertical_scroll_bar_none);
3541 /* We set this parameter before creating the X window for the
3542 frame, so we can get the geometry right from the start.
3543 However, if the window hasn't been created yet, we shouldn't
3544 call x_set_window_size. */
3545 if (FRAME_X_WINDOW (f))
3546 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3547 do_pending_window_change (0);
3551 void
3552 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3554 int wid = FRAME_COLUMN_WIDTH (f);
3556 if (NILP (arg))
3558 x_set_scroll_bar_default_width (f);
3560 if (FRAME_X_WINDOW (f))
3561 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3562 do_pending_window_change (0);
3564 else if (INTEGERP (arg) && XINT (arg) > 0
3565 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3567 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3568 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3570 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3571 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3572 if (FRAME_X_WINDOW (f))
3573 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3574 do_pending_window_change (0);
3577 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3578 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3579 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3584 /* Return non-nil if frame F wants a bitmap icon. */
3586 Lisp_Object
3587 x_icon_type (FRAME_PTR f)
3589 Lisp_Object tem;
3591 tem = assq_no_quit (Qicon_type, f->param_alist);
3592 if (CONSP (tem))
3593 return XCDR (tem);
3594 else
3595 return Qnil;
3598 void
3599 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3601 double alpha = 1.0;
3602 double newval[2];
3603 int i, ialpha;
3604 Lisp_Object item;
3606 for (i = 0; i < 2; i++)
3608 newval[i] = 1.0;
3609 if (CONSP (arg))
3611 item = CAR (arg);
3612 arg = CDR (arg);
3614 else
3615 item = arg;
3617 if (NILP (item))
3618 alpha = - 1.0;
3619 else if (FLOATP (item))
3621 alpha = XFLOAT_DATA (item);
3622 if (alpha < 0.0 || 1.0 < alpha)
3623 args_out_of_range (make_float (0.0), make_float (1.0));
3625 else if (INTEGERP (item))
3627 ialpha = XINT (item);
3628 if (ialpha < 0 || 100 < ialpha)
3629 args_out_of_range (make_number (0), make_number (100));
3630 else
3631 alpha = ialpha / 100.0;
3633 else
3634 wrong_type_argument (Qnumberp, item);
3635 newval[i] = alpha;
3638 for (i = 0; i < 2; i++)
3639 f->alpha[i] = newval[i];
3641 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3642 BLOCK_INPUT;
3643 x_set_frame_alpha (f);
3644 UNBLOCK_INPUT;
3645 #endif
3647 return;
3651 /* Subroutines of creating an X frame. */
3653 /* Make sure that Vx_resource_name is set to a reasonable value.
3654 Fix it up, or set it to `emacs' if it is too hopeless. */
3656 void
3657 validate_x_resource_name (void)
3659 int len = 0;
3660 /* Number of valid characters in the resource name. */
3661 int good_count = 0;
3662 /* Number of invalid characters in the resource name. */
3663 int bad_count = 0;
3664 Lisp_Object new;
3665 int i;
3667 if (!STRINGP (Vx_resource_class))
3668 Vx_resource_class = build_string (EMACS_CLASS);
3670 if (STRINGP (Vx_resource_name))
3672 unsigned char *p = SDATA (Vx_resource_name);
3674 len = SBYTES (Vx_resource_name);
3676 /* Only letters, digits, - and _ are valid in resource names.
3677 Count the valid characters and count the invalid ones. */
3678 for (i = 0; i < len; i++)
3680 int c = p[i];
3681 if (! ((c >= 'a' && c <= 'z')
3682 || (c >= 'A' && c <= 'Z')
3683 || (c >= '0' && c <= '9')
3684 || c == '-' || c == '_'))
3685 bad_count++;
3686 else
3687 good_count++;
3690 else
3691 /* Not a string => completely invalid. */
3692 bad_count = 5, good_count = 0;
3694 /* If name is valid already, return. */
3695 if (bad_count == 0)
3696 return;
3698 /* If name is entirely invalid, or nearly so, use `emacs'. */
3699 if (good_count == 0
3700 || (good_count == 1 && bad_count > 0))
3702 Vx_resource_name = build_string ("emacs");
3703 return;
3706 /* Name is partly valid. Copy it and replace the invalid characters
3707 with underscores. */
3709 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3711 for (i = 0; i < len; i++)
3713 int c = SREF (new, i);
3714 if (! ((c >= 'a' && c <= 'z')
3715 || (c >= 'A' && c <= 'Z')
3716 || (c >= '0' && c <= '9')
3717 || c == '-' || c == '_'))
3718 SSET (new, i, '_');
3723 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3724 extern Display_Info *check_x_display_info (Lisp_Object);
3727 /* Get specified attribute from resource database RDB.
3728 See Fx_get_resource below for other parameters. */
3730 static Lisp_Object
3731 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3733 register char *value;
3734 char *name_key;
3735 char *class_key;
3737 CHECK_STRING (attribute);
3738 CHECK_STRING (class);
3740 if (!NILP (component))
3741 CHECK_STRING (component);
3742 if (!NILP (subclass))
3743 CHECK_STRING (subclass);
3744 if (NILP (component) != NILP (subclass))
3745 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3747 validate_x_resource_name ();
3749 /* Allocate space for the components, the dots which separate them,
3750 and the final '\0'. Make them big enough for the worst case. */
3751 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3752 + (STRINGP (component)
3753 ? SBYTES (component) : 0)
3754 + SBYTES (attribute)
3755 + 3);
3757 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3758 + SBYTES (class)
3759 + (STRINGP (subclass)
3760 ? SBYTES (subclass) : 0)
3761 + 3);
3763 /* Start with emacs.FRAMENAME for the name (the specific one)
3764 and with `Emacs' for the class key (the general one). */
3765 strcpy (name_key, SDATA (Vx_resource_name));
3766 strcpy (class_key, SDATA (Vx_resource_class));
3768 strcat (class_key, ".");
3769 strcat (class_key, SDATA (class));
3771 if (!NILP (component))
3773 strcat (class_key, ".");
3774 strcat (class_key, SDATA (subclass));
3776 strcat (name_key, ".");
3777 strcat (name_key, SDATA (component));
3780 strcat (name_key, ".");
3781 strcat (name_key, SDATA (attribute));
3783 value = x_get_string_resource (rdb, name_key, class_key);
3785 if (value != (char *) 0 && *value)
3786 return build_string (value);
3787 else
3788 return Qnil;
3792 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3793 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3794 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3795 class, where INSTANCE is the name under which Emacs was invoked, or
3796 the name specified by the `-name' or `-rn' command-line arguments.
3798 The optional arguments COMPONENT and SUBCLASS add to the key and the
3799 class, respectively. You must specify both of them or neither.
3800 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3801 and the class is `Emacs.CLASS.SUBCLASS'. */)
3802 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3804 #ifdef HAVE_X_WINDOWS
3805 check_x ();
3806 #endif
3808 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3809 attribute, class, component, subclass);
3812 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3814 Lisp_Object
3815 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3817 return xrdb_get_resource (dpyinfo->xrdb,
3818 attribute, class, component, subclass);
3821 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3822 /* Used when C code wants a resource value. */
3823 /* Called from oldXMenu/Create.c. */
3824 char *
3825 x_get_resource_string (const char *attribute, const char *class)
3827 char *name_key;
3828 char *class_key;
3829 struct frame *sf = SELECTED_FRAME ();
3831 /* Allocate space for the components, the dots which separate them,
3832 and the final '\0'. */
3833 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3834 + strlen (attribute) + 2);
3835 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3836 + strlen (class) + 2);
3838 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3839 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3841 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3842 name_key, class_key);
3844 #endif
3846 /* Return the value of parameter PARAM.
3848 First search ALIST, then Vdefault_frame_alist, then the X defaults
3849 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3851 Convert the resource to the type specified by desired_type.
3853 If no default is specified, return Qunbound. If you call
3854 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3855 and don't let it get stored in any Lisp-visible variables! */
3857 Lisp_Object
3858 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3859 const char *attribute, const char *class, enum resource_types type)
3861 register Lisp_Object tem;
3863 tem = Fassq (param, alist);
3865 if (!NILP (tem))
3867 /* If we find this parm in ALIST, clear it out
3868 so that it won't be "left over" at the end. */
3869 Lisp_Object tail;
3870 XSETCAR (tem, Qnil);
3871 /* In case the parameter appears more than once in the alist,
3872 clear it out. */
3873 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3874 if (CONSP (XCAR (tail))
3875 && EQ (XCAR (XCAR (tail)), param))
3876 XSETCAR (XCAR (tail), Qnil);
3878 else
3879 tem = Fassq (param, Vdefault_frame_alist);
3881 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3882 look in the X resources. */
3883 if (EQ (tem, Qnil))
3885 if (attribute && dpyinfo)
3887 tem = display_x_get_resource (dpyinfo,
3888 build_string (attribute),
3889 build_string (class),
3890 Qnil, Qnil);
3892 if (NILP (tem))
3893 return Qunbound;
3895 switch (type)
3897 case RES_TYPE_NUMBER:
3898 return make_number (atoi (SDATA (tem)));
3900 case RES_TYPE_BOOLEAN_NUMBER:
3901 if (!strcmp (SDATA (tem), "on")
3902 || !strcmp (SDATA (tem), "true"))
3903 return make_number (1);
3904 return make_number (atoi (SDATA (tem)));
3905 break;
3907 case RES_TYPE_FLOAT:
3908 return make_float (atof (SDATA (tem)));
3910 case RES_TYPE_BOOLEAN:
3911 tem = Fdowncase (tem);
3912 if (!strcmp (SDATA (tem), "on")
3913 #ifdef HAVE_NS
3914 || !strcmp(SDATA(tem), "yes")
3915 #endif
3916 || !strcmp (SDATA (tem), "true"))
3917 return Qt;
3918 else
3919 return Qnil;
3921 case RES_TYPE_STRING:
3922 return tem;
3924 case RES_TYPE_SYMBOL:
3925 /* As a special case, we map the values `true' and `on'
3926 to Qt, and `false' and `off' to Qnil. */
3928 Lisp_Object lower;
3929 lower = Fdowncase (tem);
3930 if (!strcmp (SDATA (lower), "on")
3931 #ifdef HAVE_NS
3932 || !strcmp(SDATA(lower), "yes")
3933 #endif
3934 || !strcmp (SDATA (lower), "true"))
3935 return Qt;
3936 else if (!strcmp (SDATA (lower), "off")
3937 #ifdef HAVE_NS
3938 || !strcmp(SDATA(lower), "no")
3939 #endif
3940 || !strcmp (SDATA (lower), "false"))
3941 return Qnil;
3942 else
3943 return Fintern (tem, Qnil);
3946 default:
3947 abort ();
3950 else
3951 return Qunbound;
3953 return Fcdr (tem);
3956 Lisp_Object
3957 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3958 const char *attribute, const char *class,
3959 enum resource_types type)
3961 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3962 alist, param, attribute, class, type);
3965 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3967 Lisp_Object
3968 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3969 Lisp_Object param,
3970 const char *attribute, const char *class,
3971 enum resource_types type)
3973 Lisp_Object value;
3975 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3976 attribute, class, type);
3977 if (! NILP (value) && ! EQ (value, Qunbound))
3978 store_frame_param (f, param, value);
3980 return value;
3984 /* Record in frame F the specified or default value according to ALIST
3985 of the parameter named PROP (a Lisp symbol).
3986 If no value is specified for PROP, look for an X default for XPROP
3987 on the frame named NAME.
3988 If that is not found either, use the value DEFLT. */
3990 Lisp_Object
3991 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3992 Lisp_Object deflt, const char *xprop, const char *xclass,
3993 enum resource_types type)
3995 Lisp_Object tem;
3997 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3998 if (EQ (tem, Qunbound))
3999 tem = deflt;
4000 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
4001 return tem;
4007 /* NS used to define x-parse-geometry in ns-win.el, but that confused
4008 make-docfile: the documentation string in ns-win.el was used for
4009 x-parse-geometry even in non-NS builds.
4011 With two definitions of x-parse-geometry in this file, various
4012 things still get confused (eg M-x apropos documentation), so that
4013 it is best if the two definitions just share the same doc-string.
4015 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
4016 doc: /* Parse a display geometry string STRING.
4017 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
4018 The properties returned may include `top', `left', `height', and `width'.
4019 For X, the value of `left' or `top' may be an integer,
4020 or a list (+ N) meaning N pixels relative to top/left corner,
4021 or a list (- N) meaning -N pixels relative to bottom/right corner.
4022 On Nextstep, this just calls `ns-parse-geometry'. */)
4023 (Lisp_Object string)
4025 #ifdef HAVE_NS
4026 call1 (Qns_parse_geometry, string);
4027 #else
4028 int geometry, x, y;
4029 unsigned int width, height;
4030 Lisp_Object result;
4032 CHECK_STRING (string);
4034 geometry = XParseGeometry ((char *) SDATA (string),
4035 &x, &y, &width, &height);
4036 result = Qnil;
4037 if (geometry & XValue)
4039 Lisp_Object element;
4041 if (x >= 0 && (geometry & XNegative))
4042 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
4043 else if (x < 0 && ! (geometry & XNegative))
4044 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
4045 else
4046 element = Fcons (Qleft, make_number (x));
4047 result = Fcons (element, result);
4050 if (geometry & YValue)
4052 Lisp_Object element;
4054 if (y >= 0 && (geometry & YNegative))
4055 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
4056 else if (y < 0 && ! (geometry & YNegative))
4057 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
4058 else
4059 element = Fcons (Qtop, make_number (y));
4060 result = Fcons (element, result);
4063 if (geometry & WidthValue)
4064 result = Fcons (Fcons (Qwidth, make_number (width)), result);
4065 if (geometry & HeightValue)
4066 result = Fcons (Fcons (Qheight, make_number (height)), result);
4068 return result;
4069 #endif /* HAVE_NS */
4073 /* Calculate the desired size and position of frame F.
4074 Return the flags saying which aspects were specified.
4076 Also set the win_gravity and size_hint_flags of F.
4078 Adjust height for toolbar if TOOLBAR_P is 1.
4080 This function does not make the coordinates positive. */
4082 #define DEFAULT_ROWS 35
4083 #define DEFAULT_COLS 80
4086 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
4088 register Lisp_Object tem0, tem1, tem2;
4089 long window_prompting = 0;
4090 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
4092 /* Default values if we fall through.
4093 Actually, if that happens we should get
4094 window manager prompting. */
4095 SET_FRAME_COLS (f, DEFAULT_COLS);
4096 FRAME_LINES (f) = DEFAULT_ROWS;
4097 /* Window managers expect that if program-specified
4098 positions are not (0,0), they're intentional, not defaults. */
4099 f->top_pos = 0;
4100 f->left_pos = 0;
4102 /* Ensure that old new_text_cols and new_text_lines will not override the
4103 values set here. */
4104 /* ++KFS: This was specific to W32, but seems ok for all platforms */
4105 f->new_text_cols = f->new_text_lines = 0;
4107 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
4108 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
4109 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
4110 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4112 if (!EQ (tem0, Qunbound))
4114 CHECK_NUMBER (tem0);
4115 FRAME_LINES (f) = XINT (tem0);
4117 if (!EQ (tem1, Qunbound))
4119 CHECK_NUMBER (tem1);
4120 SET_FRAME_COLS (f, XINT (tem1));
4122 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4123 window_prompting |= USSize;
4124 else
4125 window_prompting |= PSize;
4128 f->scroll_bar_actual_width
4129 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4131 /* This used to be done _before_ calling x_figure_window_size, but
4132 since the height is reset here, this was really a no-op. I
4133 assume that moving it here does what Gerd intended (although he
4134 no longer can remember what that was... ++KFS, 2003-03-25. */
4136 /* Add the tool-bar height to the initial frame height so that the
4137 user gets a text display area of the size he specified with -g or
4138 via .Xdefaults. Later changes of the tool-bar height don't
4139 change the frame size. This is done so that users can create
4140 tall Emacs frames without having to guess how tall the tool-bar
4141 will get. */
4142 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4144 int margin, relief, bar_height;
4146 relief = (tool_bar_button_relief >= 0
4147 ? tool_bar_button_relief
4148 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4150 if (INTEGERP (Vtool_bar_button_margin)
4151 && XINT (Vtool_bar_button_margin) > 0)
4152 margin = XFASTINT (Vtool_bar_button_margin);
4153 else if (CONSP (Vtool_bar_button_margin)
4154 && INTEGERP (XCDR (Vtool_bar_button_margin))
4155 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
4156 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4157 else
4158 margin = 0;
4160 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4161 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4164 compute_fringe_widths (f, 0);
4166 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4167 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4169 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4170 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4171 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4172 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4174 if (EQ (tem0, Qminus))
4176 f->top_pos = 0;
4177 window_prompting |= YNegative;
4179 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4180 && CONSP (XCDR (tem0))
4181 && INTEGERP (XCAR (XCDR (tem0))))
4183 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4184 window_prompting |= YNegative;
4186 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4187 && CONSP (XCDR (tem0))
4188 && INTEGERP (XCAR (XCDR (tem0))))
4190 f->top_pos = XINT (XCAR (XCDR (tem0)));
4192 else if (EQ (tem0, Qunbound))
4193 f->top_pos = 0;
4194 else
4196 CHECK_NUMBER (tem0);
4197 f->top_pos = XINT (tem0);
4198 if (f->top_pos < 0)
4199 window_prompting |= YNegative;
4202 if (EQ (tem1, Qminus))
4204 f->left_pos = 0;
4205 window_prompting |= XNegative;
4207 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4208 && CONSP (XCDR (tem1))
4209 && INTEGERP (XCAR (XCDR (tem1))))
4211 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4212 window_prompting |= XNegative;
4214 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4215 && CONSP (XCDR (tem1))
4216 && INTEGERP (XCAR (XCDR (tem1))))
4218 f->left_pos = XINT (XCAR (XCDR (tem1)));
4220 else if (EQ (tem1, Qunbound))
4221 f->left_pos = 0;
4222 else
4224 CHECK_NUMBER (tem1);
4225 f->left_pos = XINT (tem1);
4226 if (f->left_pos < 0)
4227 window_prompting |= XNegative;
4230 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4231 window_prompting |= USPosition;
4232 else
4233 window_prompting |= PPosition;
4236 if (window_prompting & XNegative)
4238 if (window_prompting & YNegative)
4239 f->win_gravity = SouthEastGravity;
4240 else
4241 f->win_gravity = NorthEastGravity;
4243 else
4245 if (window_prompting & YNegative)
4246 f->win_gravity = SouthWestGravity;
4247 else
4248 f->win_gravity = NorthWestGravity;
4251 f->size_hint_flags = window_prompting;
4253 return window_prompting;
4258 #endif /* HAVE_WINDOW_SYSTEM */
4260 void
4261 frame_make_pointer_invisible (void)
4263 if (! NILP (Vmake_pointer_invisible))
4265 struct frame *f;
4266 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4267 return;
4269 f = SELECTED_FRAME ();
4270 if (f && !f->pointer_invisible
4271 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4273 f->mouse_moved = 0;
4274 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4275 f->pointer_invisible = 1;
4280 void
4281 frame_make_pointer_visible (void)
4283 /* We don't check Vmake_pointer_invisible here in case the
4284 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4285 struct frame *f;
4287 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4288 return;
4290 f = SELECTED_FRAME ();
4291 if (f && f->pointer_invisible && f->mouse_moved
4292 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4294 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4295 f->pointer_invisible = 0;
4301 /***********************************************************************
4302 Initialization
4303 ***********************************************************************/
4305 void
4306 syms_of_frame (void)
4308 Qframep = intern_c_string ("framep");
4309 staticpro (&Qframep);
4310 Qframe_live_p = intern_c_string ("frame-live-p");
4311 staticpro (&Qframe_live_p);
4312 Qexplicit_name = intern_c_string ("explicit-name");
4313 staticpro (&Qexplicit_name);
4314 Qheight = intern_c_string ("height");
4315 staticpro (&Qheight);
4316 Qicon = intern_c_string ("icon");
4317 staticpro (&Qicon);
4318 Qminibuffer = intern_c_string ("minibuffer");
4319 staticpro (&Qminibuffer);
4320 Qmodeline = intern_c_string ("modeline");
4321 staticpro (&Qmodeline);
4322 Qonly = intern_c_string ("only");
4323 staticpro (&Qonly);
4324 Qwidth = intern_c_string ("width");
4325 staticpro (&Qwidth);
4326 Qgeometry = intern_c_string ("geometry");
4327 staticpro (&Qgeometry);
4328 Qicon_left = intern_c_string ("icon-left");
4329 staticpro (&Qicon_left);
4330 Qicon_top = intern_c_string ("icon-top");
4331 staticpro (&Qicon_top);
4332 Qtooltip = intern_c_string ("tooltip");
4333 staticpro (&Qtooltip);
4334 Qleft = intern_c_string ("left");
4335 staticpro (&Qleft);
4336 Qright = intern_c_string ("right");
4337 staticpro (&Qright);
4338 Quser_position = intern_c_string ("user-position");
4339 staticpro (&Quser_position);
4340 Quser_size = intern_c_string ("user-size");
4341 staticpro (&Quser_size);
4342 Qwindow_id = intern_c_string ("window-id");
4343 staticpro (&Qwindow_id);
4344 #ifdef HAVE_X_WINDOWS
4345 Qouter_window_id = intern_c_string ("outer-window-id");
4346 staticpro (&Qouter_window_id);
4347 #endif
4348 Qparent_id = intern_c_string ("parent-id");
4349 staticpro (&Qparent_id);
4350 Qx = intern_c_string ("x");
4351 staticpro (&Qx);
4352 Qw32 = intern_c_string ("w32");
4353 staticpro (&Qw32);
4354 Qpc = intern_c_string ("pc");
4355 staticpro (&Qpc);
4356 Qmac = intern_c_string ("mac");
4357 staticpro (&Qmac);
4358 Qns = intern_c_string ("ns");
4359 staticpro (&Qns);
4360 Qvisible = intern_c_string ("visible");
4361 staticpro (&Qvisible);
4362 Qbuffer_predicate = intern_c_string ("buffer-predicate");
4363 staticpro (&Qbuffer_predicate);
4364 Qbuffer_list = intern_c_string ("buffer-list");
4365 staticpro (&Qbuffer_list);
4366 Qburied_buffer_list = intern_c_string ("buried-buffer-list");
4367 staticpro (&Qburied_buffer_list);
4368 Qdisplay_type = intern_c_string ("display-type");
4369 staticpro (&Qdisplay_type);
4370 Qbackground_mode = intern_c_string ("background-mode");
4371 staticpro (&Qbackground_mode);
4372 Qnoelisp = intern_c_string ("noelisp");
4373 staticpro (&Qnoelisp);
4374 Qtty_color_mode = intern_c_string ("tty-color-mode");
4375 staticpro (&Qtty_color_mode);
4376 Qtty = intern_c_string ("tty");
4377 staticpro (&Qtty);
4378 Qtty_type = intern_c_string ("tty-type");
4379 staticpro (&Qtty_type);
4381 Qface_set_after_frame_default = intern_c_string ("face-set-after-frame-default");
4382 staticpro (&Qface_set_after_frame_default);
4384 Qfullwidth = intern_c_string ("fullwidth");
4385 staticpro (&Qfullwidth);
4386 Qfullheight = intern_c_string ("fullheight");
4387 staticpro (&Qfullheight);
4388 Qfullboth = intern_c_string ("fullboth");
4389 staticpro (&Qfullboth);
4390 Qmaximized = intern_c_string ("maximized");
4391 staticpro (&Qmaximized);
4392 Qx_resource_name = intern_c_string ("x-resource-name");
4393 staticpro (&Qx_resource_name);
4395 Qx_frame_parameter = intern_c_string ("x-frame-parameter");
4396 staticpro (&Qx_frame_parameter);
4398 Qterminal = intern_c_string ("terminal");
4399 staticpro (&Qterminal);
4400 Qterminal_live_p = intern_c_string ("terminal-live-p");
4401 staticpro (&Qterminal_live_p);
4403 #ifdef HAVE_NS
4404 Qns_parse_geometry = intern_c_string ("ns-parse-geometry");
4405 staticpro (&Qns_parse_geometry);
4406 #endif
4409 int i;
4411 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4413 Lisp_Object v = intern_c_string (frame_parms[i].name);
4414 if (frame_parms[i].variable)
4416 *frame_parms[i].variable = v;
4417 staticpro (frame_parms[i].variable);
4419 Fput (v, Qx_frame_parameter, make_number (i));
4423 #ifdef HAVE_WINDOW_SYSTEM
4424 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4425 doc: /* The name Emacs uses to look up X resources.
4426 `x-get-resource' uses this as the first component of the instance name
4427 when requesting resource values.
4428 Emacs initially sets `x-resource-name' to the name under which Emacs
4429 was invoked, or to the value specified with the `-name' or `-rn'
4430 switches, if present.
4432 It may be useful to bind this variable locally around a call
4433 to `x-get-resource'. See also the variable `x-resource-class'. */);
4434 Vx_resource_name = Qnil;
4436 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4437 doc: /* The class Emacs uses to look up X resources.
4438 `x-get-resource' uses this as the first component of the instance class
4439 when requesting resource values.
4441 Emacs initially sets `x-resource-class' to "Emacs".
4443 Setting this variable permanently is not a reasonable thing to do,
4444 but binding this variable locally around a call to `x-get-resource'
4445 is a reasonable practice. See also the variable `x-resource-name'. */);
4446 Vx_resource_class = build_string (EMACS_CLASS);
4448 DEFVAR_LISP ("frame-alpha-lower-limit", &Vframe_alpha_lower_limit,
4449 doc: /* The lower limit of the frame opacity (alpha transparency).
4450 The value should range from 0 (invisible) to 100 (completely opaque).
4451 You can also use a floating number between 0.0 and 1.0.
4452 The default is 20. */);
4453 Vframe_alpha_lower_limit = make_number (20);
4454 #endif
4456 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4457 doc: /* Alist of default values for frame creation.
4458 These may be set in your init file, like this:
4459 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4460 These override values given in window system configuration data,
4461 including X Windows' defaults database.
4462 For values specific to the first Emacs frame, see `initial-frame-alist'.
4463 For window-system specific values, see `window-system-default-frame-alist'.
4464 For values specific to the separate minibuffer frame, see
4465 `minibuffer-frame-alist'.
4466 The `menu-bar-lines' element of the list controls whether new frames
4467 have menu bars; `menu-bar-mode' works by altering this element.
4468 Setting this variable does not affect existing frames, only new ones. */);
4469 Vdefault_frame_alist = Qnil;
4471 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4472 doc: /* Default position of scroll bars on this window-system. */);
4473 #ifdef HAVE_WINDOW_SYSTEM
4474 #if defined(HAVE_NTGUI) || defined(NS_IMPL_COCOA) || (defined(USE_GTK) && defined(USE_TOOLKIT_SCROLL_BARS))
4475 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4476 default. */
4477 Vdefault_frame_scroll_bars = Qright;
4478 #else
4479 Vdefault_frame_scroll_bars = Qleft;
4480 #endif
4481 #else
4482 Vdefault_frame_scroll_bars = Qnil;
4483 #endif
4485 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4486 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4488 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4489 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4490 `mouse-position' calls this function, passing its usual return value as
4491 argument, and returns whatever this function returns.
4492 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4493 which need to do mouse handling at the Lisp level. */);
4494 Vmouse_position_function = Qnil;
4496 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4497 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4498 If the value is an integer, highlighting is only shown after moving the
4499 mouse, while keyboard input turns off the highlight even when the mouse
4500 is over the clickable text. However, the mouse shape still indicates
4501 when the mouse is over clickable text. */);
4502 Vmouse_highlight = Qt;
4504 DEFVAR_LISP ("make-pointer-invisible", &Vmake_pointer_invisible,
4505 doc: /* If non-nil, make pointer invisible while typing.
4506 The pointer becomes visible again when the mouse is moved. */);
4507 Vmake_pointer_invisible = Qt;
4509 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4510 doc: /* Functions to be run before deleting a frame.
4511 The functions are run with one arg, the frame to be deleted.
4512 See `delete-frame'.
4514 Note that functions in this list may be called just before the frame is
4515 actually deleted, or some time later (or even both when an earlier function
4516 in `delete-frame-functions' (indirectly) calls `delete-frame'
4517 recursively). */);
4518 Vdelete_frame_functions = Qnil;
4519 Qdelete_frame_functions = intern_c_string ("delete-frame-functions");
4520 staticpro (&Qdelete_frame_functions);
4522 DEFVAR_LISP ("menu-bar-mode", &Vmenu_bar_mode,
4523 doc: /* Non-nil if Menu-Bar mode is enabled. */);
4524 Vmenu_bar_mode = Qt;
4526 DEFVAR_LISP ("tool-bar-mode", &Vtool_bar_mode,
4527 doc: /* Non-nil if Tool-Bar mode is enabled. */);
4528 Vtool_bar_mode = Qt;
4530 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4531 doc: /* Minibufferless frames use this frame's minibuffer.
4533 Emacs cannot create minibufferless frames unless this is set to an
4534 appropriate surrogate.
4536 Emacs consults this variable only when creating minibufferless
4537 frames; once the frame is created, it sticks with its assigned
4538 minibuffer, no matter what this variable is set to. This means that
4539 this variable doesn't necessarily say anything meaningful about the
4540 current set of frames, or where the minibuffer is currently being
4541 displayed.
4543 This variable is local to the current terminal and cannot be buffer-local. */);
4545 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4546 doc: /* Non-nil if window system changes focus when you move the mouse.
4547 You should set this variable to tell Emacs how your window manager
4548 handles focus, since there is no way in general for Emacs to find out
4549 automatically. See also `mouse-autoselect-window'. */);
4550 #ifdef HAVE_WINDOW_SYSTEM
4551 #if defined(HAVE_NTGUI) || defined(HAVE_NS)
4552 focus_follows_mouse = 0;
4553 #else
4554 focus_follows_mouse = 1;
4555 #endif
4556 #else
4557 focus_follows_mouse = 0;
4558 #endif
4560 staticpro (&Vframe_list);
4562 defsubr (&Sactive_minibuffer_window);
4563 defsubr (&Sframep);
4564 defsubr (&Sframe_live_p);
4565 defsubr (&Swindow_system);
4566 defsubr (&Smake_terminal_frame);
4567 defsubr (&Shandle_switch_frame);
4568 defsubr (&Sselect_frame);
4569 defsubr (&Sselected_frame);
4570 defsubr (&Swindow_frame);
4571 defsubr (&Sframe_root_window);
4572 defsubr (&Sframe_first_window);
4573 defsubr (&Sframe_selected_window);
4574 defsubr (&Sset_frame_selected_window);
4575 defsubr (&Sframe_list);
4576 defsubr (&Snext_frame);
4577 defsubr (&Sprevious_frame);
4578 defsubr (&Sdelete_frame);
4579 defsubr (&Smouse_position);
4580 defsubr (&Smouse_pixel_position);
4581 defsubr (&Sset_mouse_position);
4582 defsubr (&Sset_mouse_pixel_position);
4583 #if 0
4584 defsubr (&Sframe_configuration);
4585 defsubr (&Srestore_frame_configuration);
4586 #endif
4587 defsubr (&Smake_frame_visible);
4588 defsubr (&Smake_frame_invisible);
4589 defsubr (&Siconify_frame);
4590 defsubr (&Sframe_visible_p);
4591 defsubr (&Svisible_frame_list);
4592 defsubr (&Sraise_frame);
4593 defsubr (&Slower_frame);
4594 defsubr (&Sredirect_frame_focus);
4595 defsubr (&Sframe_focus);
4596 defsubr (&Sframe_parameters);
4597 defsubr (&Sframe_parameter);
4598 defsubr (&Smodify_frame_parameters);
4599 defsubr (&Sframe_char_height);
4600 defsubr (&Sframe_char_width);
4601 defsubr (&Sframe_pixel_height);
4602 defsubr (&Sframe_pixel_width);
4603 defsubr (&Sset_frame_height);
4604 defsubr (&Sset_frame_width);
4605 defsubr (&Sset_frame_size);
4606 defsubr (&Sset_frame_position);
4608 #ifdef HAVE_WINDOW_SYSTEM
4609 defsubr (&Sx_get_resource);
4610 defsubr (&Sx_parse_geometry);
4611 #endif
4615 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4616 (do not change this comment) */