Correct typo.
[emacs.git] / src / frame.c
blobdf98475d7b308a68c14769b3001bcdd792c61449
1 /* Generic frame functions.
2 Copyright (C) 1993, 1994, 1995, 1997, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007 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, or (at your option)
10 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; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 #include <config.h>
24 #include <stdio.h>
25 #include "lisp.h"
26 #include "charset.h"
27 #ifdef HAVE_X_WINDOWS
28 #include "xterm.h"
29 #endif
30 #ifdef WINDOWSNT
31 #include "w32term.h"
32 #endif
33 #ifdef MAC_OS
34 #include "macterm.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 #ifdef HAVE_WINDOW_SYSTEM
42 #include "fontset.h"
43 #endif
44 #include "blockinput.h"
45 #include "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #ifdef MSDOS
49 #include "msdos.h"
50 #include "dosfns.h"
51 #endif
54 #ifdef HAVE_WINDOW_SYSTEM
56 /* The name we're using in resource queries. Most often "emacs". */
58 Lisp_Object Vx_resource_name;
60 /* The application class we're using in resource queries.
61 Normally "Emacs". */
63 Lisp_Object Vx_resource_class;
65 #endif
67 Lisp_Object Qframep, Qframe_live_p;
68 Lisp_Object Qicon, Qmodeline;
69 Lisp_Object Qonly;
70 Lisp_Object Qx, Qw32, Qmac, Qpc;
71 Lisp_Object Qvisible;
72 Lisp_Object Qdisplay_type;
73 Lisp_Object Qbackground_mode;
75 Lisp_Object Qx_frame_parameter;
76 Lisp_Object Qx_resource_name;
78 /* Frame parameters (set or reported). */
80 Lisp_Object Qauto_raise, Qauto_lower;
81 Lisp_Object Qborder_color, Qborder_width;
82 Lisp_Object Qcursor_color, Qcursor_type;
83 Lisp_Object Qgeometry; /* Not used */
84 Lisp_Object Qheight, Qwidth;
85 Lisp_Object Qleft, Qright;
86 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
87 Lisp_Object Qinternal_border_width;
88 Lisp_Object Qmouse_color;
89 Lisp_Object Qminibuffer;
90 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
91 Lisp_Object Qvisibility;
92 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
93 Lisp_Object Qscreen_gamma;
94 Lisp_Object Qline_spacing;
95 Lisp_Object Quser_position, Quser_size;
96 Lisp_Object Qwait_for_wm;
97 Lisp_Object Qwindow_id;
98 #ifdef HAVE_X_WINDOWS
99 Lisp_Object Qouter_window_id;
100 #endif
101 Lisp_Object Qparent_id;
102 Lisp_Object Qtitle, Qname;
103 Lisp_Object Qexplicit_name;
104 Lisp_Object Qunsplittable;
105 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines;
106 Lisp_Object Qleft_fringe, Qright_fringe;
107 Lisp_Object Qbuffer_predicate, Qbuffer_list;
108 Lisp_Object Qtty_color_mode;
110 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth;
112 Lisp_Object Qinhibit_face_set_after_frame_default;
113 Lisp_Object Qface_set_after_frame_default;
116 Lisp_Object Vterminal_frame;
117 Lisp_Object Vdefault_frame_alist;
118 Lisp_Object Vdefault_frame_scroll_bars;
119 Lisp_Object Vmouse_position_function;
120 Lisp_Object Vmouse_highlight;
121 Lisp_Object Vdelete_frame_functions;
123 int focus_follows_mouse;
125 static void
126 set_menu_bar_lines_1 (window, n)
127 Lisp_Object window;
128 int n;
130 struct window *w = XWINDOW (window);
132 XSETFASTINT (w->last_modified, 0);
133 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
134 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
136 if (INTEGERP (w->orig_top_line))
137 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
138 if (INTEGERP (w->orig_total_lines))
139 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
141 /* Handle just the top child in a vertical split. */
142 if (!NILP (w->vchild))
143 set_menu_bar_lines_1 (w->vchild, n);
145 /* Adjust all children in a horizontal split. */
146 for (window = w->hchild; !NILP (window); window = w->next)
148 w = XWINDOW (window);
149 set_menu_bar_lines_1 (window, n);
153 void
154 set_menu_bar_lines (f, value, oldval)
155 struct frame *f;
156 Lisp_Object value, oldval;
158 int nlines;
159 int olines = FRAME_MENU_BAR_LINES (f);
161 /* Right now, menu bars don't work properly in minibuf-only frames;
162 most of the commands try to apply themselves to the minibuffer
163 frame itself, and get an error because you can't switch buffers
164 in or split the minibuffer window. */
165 if (FRAME_MINIBUF_ONLY_P (f))
166 return;
168 if (INTEGERP (value))
169 nlines = XINT (value);
170 else
171 nlines = 0;
173 if (nlines != olines)
175 windows_or_buffers_changed++;
176 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
177 FRAME_MENU_BAR_LINES (f) = nlines;
178 set_menu_bar_lines_1 (f->root_window, nlines - olines);
179 adjust_glyphs (f);
183 Lisp_Object Vemacs_iconified;
184 Lisp_Object Vframe_list;
186 struct x_output tty_display;
188 extern Lisp_Object Vminibuffer_list;
189 extern Lisp_Object get_minibuffer ();
190 extern Lisp_Object Fhandle_switch_frame ();
191 extern Lisp_Object Fredirect_frame_focus ();
192 extern Lisp_Object x_get_focus_frame ();
194 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
195 doc: /* Return non-nil if OBJECT is a frame.
196 Value is t for a termcap frame (a character-only terminal),
197 `x' for an Emacs frame that is really an X window,
198 `w32' for an Emacs frame that is a window on MS-Windows display,
199 `mac' for an Emacs frame on a Macintosh display,
200 `pc' for a direct-write MS-DOS frame.
201 See also `frame-live-p'. */)
202 (object)
203 Lisp_Object object;
205 if (!FRAMEP (object))
206 return Qnil;
207 switch (XFRAME (object)->output_method)
209 case output_termcap:
210 return Qt;
211 case output_x_window:
212 return Qx;
213 case output_w32:
214 return Qw32;
215 case output_msdos_raw:
216 return Qpc;
217 case output_mac:
218 return Qmac;
219 default:
220 abort ();
224 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
225 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
226 Value is nil if OBJECT is not a live frame. If object is a live
227 frame, the return value indicates what sort of output device it is
228 displayed on. See the documentation of `framep' for possible
229 return values. */)
230 (object)
231 Lisp_Object object;
233 return ((FRAMEP (object)
234 && FRAME_LIVE_P (XFRAME (object)))
235 ? Fframep (object)
236 : Qnil);
239 struct frame *
240 make_frame (mini_p)
241 int mini_p;
243 Lisp_Object frame;
244 register struct frame *f;
245 register Lisp_Object root_window;
246 register Lisp_Object mini_window;
248 f = allocate_frame ();
249 XSETFRAME (frame, f);
251 f->desired_matrix = 0;
252 f->current_matrix = 0;
253 f->desired_pool = 0;
254 f->current_pool = 0;
255 f->glyphs_initialized_p = 0;
256 f->decode_mode_spec_buffer = 0;
257 f->visible = 0;
258 f->async_visible = 0;
259 f->output_data.nothing = 0;
260 f->iconified = 0;
261 f->async_iconified = 0;
262 f->wants_modeline = 1;
263 f->auto_raise = 0;
264 f->auto_lower = 0;
265 f->no_split = 0;
266 f->garbaged = 1;
267 f->has_minibuffer = mini_p;
268 f->focus_frame = Qnil;
269 f->explicit_name = 0;
270 f->can_have_scroll_bars = 0;
271 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
272 f->param_alist = Qnil;
273 f->scroll_bars = Qnil;
274 f->condemned_scroll_bars = Qnil;
275 f->face_alist = Qnil;
276 f->face_cache = NULL;
277 f->menu_bar_items = Qnil;
278 f->menu_bar_vector = Qnil;
279 f->menu_bar_items_used = 0;
280 f->buffer_predicate = Qnil;
281 f->buffer_list = Qnil;
282 #ifdef MULTI_KBOARD
283 f->kboard = initial_kboard;
284 #endif
285 f->namebuf = 0;
286 f->title = Qnil;
287 f->menu_bar_window = Qnil;
288 f->tool_bar_window = Qnil;
289 f->tool_bar_items = Qnil;
290 f->desired_tool_bar_string = f->current_tool_bar_string = Qnil;
291 f->n_tool_bar_items = 0;
292 f->left_fringe_width = f->right_fringe_width = 0;
293 f->fringe_cols = 0;
294 f->scroll_bar_actual_width = 0;
295 f->border_width = 0;
296 f->internal_border_width = 0;
297 f->column_width = 1; /* !FRAME_WINDOW_P value */
298 f->line_height = 1; /* !FRAME_WINDOW_P value */
299 f->x_pixels_diff = f->y_pixels_diff = 0;
300 #ifdef HAVE_WINDOW_SYSTEM
301 f->want_fullscreen = FULLSCREEN_NONE;
302 #endif
303 f->size_hint_flags = 0;
304 f->win_gravity = 0;
306 root_window = make_window ();
307 if (mini_p)
309 mini_window = make_window ();
310 XWINDOW (root_window)->next = mini_window;
311 XWINDOW (mini_window)->prev = root_window;
312 XWINDOW (mini_window)->mini_p = Qt;
313 XWINDOW (mini_window)->frame = frame;
314 f->minibuffer_window = mini_window;
316 else
318 mini_window = Qnil;
319 XWINDOW (root_window)->next = Qnil;
320 f->minibuffer_window = Qnil;
323 XWINDOW (root_window)->frame = frame;
325 /* 10 is arbitrary,
326 just so that there is "something there."
327 Correct size will be set up later with change_frame_size. */
329 SET_FRAME_COLS (f, 10);
330 FRAME_LINES (f) = 10;
332 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
333 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
335 if (mini_p)
337 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
338 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
339 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
342 /* Choose a buffer for the frame's root window. */
344 Lisp_Object buf;
346 XWINDOW (root_window)->buffer = Qt;
347 buf = Fcurrent_buffer ();
348 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
349 a space), try to find another one. */
350 if (SREF (Fbuffer_name (buf), 0) == ' ')
351 buf = Fother_buffer (buf, Qnil, Qnil);
353 /* Use set_window_buffer, not Fset_window_buffer, and don't let
354 hooks be run by it. The reason is that the whole frame/window
355 arrangement is not yet fully intialized at this point. Windows
356 don't have the right size, glyph matrices aren't initialized
357 etc. Running Lisp functions at this point surely ends in a
358 SEGV. */
359 set_window_buffer (root_window, buf, 0, 0);
360 f->buffer_list = Fcons (buf, Qnil);
363 if (mini_p)
365 XWINDOW (mini_window)->buffer = Qt;
366 set_window_buffer (mini_window,
367 (NILP (Vminibuffer_list)
368 ? get_minibuffer (0)
369 : Fcar (Vminibuffer_list)),
370 0, 0);
373 f->root_window = root_window;
374 f->selected_window = root_window;
375 /* Make sure this window seems more recently used than
376 a newly-created, never-selected window. */
377 ++window_select_count;
378 XSETFASTINT (XWINDOW (f->selected_window)->use_time, window_select_count);
380 f->default_face_done_p = 0;
382 return f;
385 #ifdef HAVE_WINDOW_SYSTEM
386 /* Make a frame using a separate minibuffer window on another frame.
387 MINI_WINDOW is the minibuffer window to use. nil means use the
388 default (the global minibuffer). */
390 struct frame *
391 make_frame_without_minibuffer (mini_window, kb, display)
392 register Lisp_Object mini_window;
393 KBOARD *kb;
394 Lisp_Object display;
396 register struct frame *f;
397 struct gcpro gcpro1;
399 if (!NILP (mini_window))
400 CHECK_LIVE_WINDOW (mini_window);
402 #ifdef MULTI_KBOARD
403 if (!NILP (mini_window)
404 && XFRAME (XWINDOW (mini_window)->frame)->kboard != kb)
405 error ("Frame and minibuffer must be on the same display");
406 #endif
408 /* Make a frame containing just a root window. */
409 f = make_frame (0);
411 if (NILP (mini_window))
413 /* Use default-minibuffer-frame if possible. */
414 if (!FRAMEP (kb->Vdefault_minibuffer_frame)
415 || ! FRAME_LIVE_P (XFRAME (kb->Vdefault_minibuffer_frame)))
417 Lisp_Object frame_dummy;
419 XSETFRAME (frame_dummy, f);
420 GCPRO1 (frame_dummy);
421 /* If there's no minibuffer frame to use, create one. */
422 kb->Vdefault_minibuffer_frame =
423 call1 (intern ("make-initial-minibuffer-frame"), display);
424 UNGCPRO;
427 mini_window = XFRAME (kb->Vdefault_minibuffer_frame)->minibuffer_window;
430 f->minibuffer_window = mini_window;
432 /* Make the chosen minibuffer window display the proper minibuffer,
433 unless it is already showing a minibuffer. */
434 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
435 Fset_window_buffer (mini_window,
436 (NILP (Vminibuffer_list)
437 ? get_minibuffer (0)
438 : Fcar (Vminibuffer_list)), Qnil);
439 return f;
442 /* Make a frame containing only a minibuffer window. */
444 struct frame *
445 make_minibuffer_frame ()
447 /* First make a frame containing just a root window, no minibuffer. */
449 register struct frame *f = make_frame (0);
450 register Lisp_Object mini_window;
451 register Lisp_Object frame;
453 XSETFRAME (frame, f);
455 f->auto_raise = 0;
456 f->auto_lower = 0;
457 f->no_split = 1;
458 f->wants_modeline = 0;
459 f->has_minibuffer = 1;
461 /* Now label the root window as also being the minibuffer.
462 Avoid infinite looping on the window chain by marking next pointer
463 as nil. */
465 mini_window = f->minibuffer_window = f->root_window;
466 XWINDOW (mini_window)->mini_p = Qt;
467 XWINDOW (mini_window)->next = Qnil;
468 XWINDOW (mini_window)->prev = Qnil;
469 XWINDOW (mini_window)->frame = frame;
471 /* Put the proper buffer in that window. */
473 Fset_window_buffer (mini_window,
474 (NILP (Vminibuffer_list)
475 ? get_minibuffer (0)
476 : Fcar (Vminibuffer_list)), Qnil);
477 return f;
479 #endif /* HAVE_WINDOW_SYSTEM */
481 /* Construct a frame that refers to the terminal (stdin and stdout). */
483 static int terminal_frame_count;
485 struct frame *
486 make_terminal_frame ()
488 register struct frame *f;
489 Lisp_Object frame;
490 char name[20];
492 #ifdef MULTI_KBOARD
493 if (!initial_kboard)
495 initial_kboard = (KBOARD *) xmalloc (sizeof (KBOARD));
496 init_kboard (initial_kboard);
497 initial_kboard->next_kboard = all_kboards;
498 all_kboards = initial_kboard;
500 #endif
502 /* The first call must initialize Vframe_list. */
503 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
504 Vframe_list = Qnil;
506 f = make_frame (1);
508 XSETFRAME (frame, f);
509 Vframe_list = Fcons (frame, Vframe_list);
511 terminal_frame_count++;
512 sprintf (name, "F%d", terminal_frame_count);
513 f->name = build_string (name);
515 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
516 f->async_visible = 1; /* Don't let visible be cleared later. */
517 #ifdef MSDOS
518 f->output_data.x = &the_only_x_display;
519 if (!inhibit_window_system
520 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
521 || XFRAME (selected_frame)->output_method == output_msdos_raw))
523 f->output_method = output_msdos_raw;
524 /* This initialization of foreground and background pixels is
525 only important for the initial frame created in temacs. If
526 we don't do that, we get black background and foreground in
527 the dumped Emacs because the_only_x_display is a static
528 variable, hence it is born all-zeroes, and zero is the code
529 for the black color. Other frames all inherit their pixels
530 from what's already in the_only_x_display. */
531 if ((!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
532 && f->output_data.x->background_pixel == 0
533 && f->output_data.x->foreground_pixel == 0)
535 f->output_data.x->background_pixel = FACE_TTY_DEFAULT_BG_COLOR;
536 f->output_data.x->foreground_pixel = FACE_TTY_DEFAULT_FG_COLOR;
539 else
540 f->output_method = output_termcap;
541 #else
542 #ifdef WINDOWSNT
543 f->output_method = output_termcap;
544 f->output_data.x = &tty_display;
545 #else
546 #ifdef MAC_OS8
547 make_mac_terminal_frame (f);
548 #else
549 f->output_data.x = &tty_display;
550 #ifdef CANNOT_DUMP
551 FRAME_FOREGROUND_PIXEL(f) = FACE_TTY_DEFAULT_FG_COLOR;
552 FRAME_BACKGROUND_PIXEL(f) = FACE_TTY_DEFAULT_BG_COLOR;
553 #endif
554 #endif /* MAC_OS8 */
555 #endif /* WINDOWSNT */
556 #endif /* MSDOS */
558 if (!noninteractive)
559 init_frame_faces (f);
561 return f;
564 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
565 1, 1, 0,
566 doc: /* Create an additional terminal frame.
567 You can create multiple frames on a text-only terminal in this way.
568 Only the selected terminal frame is actually displayed.
569 This function takes one argument, an alist specifying frame parameters.
570 In practice, generally you don't need to specify any parameters.
571 Note that changing the size of one terminal frame automatically affects all. */)
572 (parms)
573 Lisp_Object parms;
575 struct frame *f;
576 Lisp_Object frame, tem;
577 struct frame *sf = SELECTED_FRAME ();
579 #ifdef MSDOS
580 if (sf->output_method != output_msdos_raw
581 && sf->output_method != output_termcap)
582 abort ();
583 #else /* not MSDOS */
585 #ifdef MAC_OS
586 if (sf->output_method != output_mac)
587 error ("Not running on a Macintosh screen; cannot make a new Macintosh frame");
588 #else
589 if (sf->output_method != output_termcap)
590 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
591 #endif
592 #endif /* not MSDOS */
594 f = make_terminal_frame ();
596 change_frame_size (f, FRAME_LINES (sf),
597 FRAME_COLS (sf), 0, 0, 0);
598 adjust_glyphs (f);
599 calculate_costs (f);
600 XSETFRAME (frame, f);
601 Fmodify_frame_parameters (frame, Vdefault_frame_alist);
602 Fmodify_frame_parameters (frame, parms);
604 /* Make the frame face alist be frame-specific, so that each
605 frame could change its face definitions independently. */
606 f->face_alist = Fcopy_alist (sf->face_alist);
607 /* Simple Fcopy_alist isn't enough, because we need the contents of
608 the vectors which are the CDRs of associations in face_alist to
609 be copied as well. */
610 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
611 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
612 return frame;
616 /* Perform the switch to frame FRAME.
618 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
619 FRAME1 as frame.
621 If TRACK is non-zero and the frame that currently has the focus
622 redirects its focus to the selected frame, redirect that focused
623 frame's focus to FRAME instead.
625 FOR_DELETION non-zero means that the selected frame is being
626 deleted, which includes the possibility that the frame's display
627 is dead. */
629 Lisp_Object
630 do_switch_frame (frame, track, for_deletion)
631 Lisp_Object frame;
632 int track, for_deletion;
634 struct frame *sf = SELECTED_FRAME ();
636 /* If FRAME is a switch-frame event, extract the frame we should
637 switch to. */
638 if (CONSP (frame)
639 && EQ (XCAR (frame), Qswitch_frame)
640 && CONSP (XCDR (frame)))
641 frame = XCAR (XCDR (frame));
643 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
644 a switch-frame event to arrive after a frame is no longer live,
645 especially when deleting the initial frame during startup. */
646 CHECK_FRAME (frame);
647 if (! FRAME_LIVE_P (XFRAME (frame)))
648 return Qnil;
650 if (sf == XFRAME (frame))
651 return frame;
653 /* This is too greedy; it causes inappropriate focus redirection
654 that's hard to get rid of. */
655 #if 0
656 /* If a frame's focus has been redirected toward the currently
657 selected frame, we should change the redirection to point to the
658 newly selected frame. This means that if the focus is redirected
659 from a minibufferless frame to a surrogate minibuffer frame, we
660 can use `other-window' to switch between all the frames using
661 that minibuffer frame, and the focus redirection will follow us
662 around. */
663 if (track)
665 Lisp_Object tail;
667 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
669 Lisp_Object focus;
671 if (!FRAMEP (XCAR (tail)))
672 abort ();
674 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
676 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
677 Fredirect_frame_focus (XCAR (tail), frame);
680 #else /* ! 0 */
681 /* Instead, apply it only to the frame we're pointing to. */
682 #ifdef HAVE_WINDOW_SYSTEM
683 if (track && FRAME_WINDOW_P (XFRAME (frame)))
685 Lisp_Object focus, xfocus;
687 xfocus = x_get_focus_frame (XFRAME (frame));
688 if (FRAMEP (xfocus))
690 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
691 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
692 Fredirect_frame_focus (xfocus, frame);
695 #endif /* HAVE_X_WINDOWS */
696 #endif /* ! 0 */
698 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
699 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
701 selected_frame = frame;
702 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
703 last_nonminibuf_frame = XFRAME (selected_frame);
705 Fselect_window (XFRAME (frame)->selected_window, Qnil);
707 #ifndef WINDOWSNT
708 /* Make sure to switch the tty color mode to that of the newly
709 selected frame. */
710 sf = SELECTED_FRAME ();
711 if (FRAME_TERMCAP_P (sf))
713 Lisp_Object color_mode_spec, color_mode;
715 color_mode_spec = assq_no_quit (Qtty_color_mode, sf->param_alist);
716 if (CONSP (color_mode_spec))
717 color_mode = XCDR (color_mode_spec);
718 else
719 color_mode = make_number (0);
720 set_tty_color_mode (sf, color_mode);
722 #endif /* !WINDOWSNT */
724 /* We want to make sure that the next event generates a frame-switch
725 event to the appropriate frame. This seems kludgy to me, but
726 before you take it out, make sure that evaluating something like
727 (select-window (frame-root-window (new-frame))) doesn't end up
728 with your typing being interpreted in the new frame instead of
729 the one you're actually typing in. */
730 internal_last_event_frame = Qnil;
732 return frame;
735 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 1, "e",
736 doc: /* Select the frame FRAME.
737 Subsequent editing commands apply to its selected window.
738 The selection of FRAME lasts until the next time the user does
739 something to select a different frame, or until the next time this
740 function is called. If you are using a window system, the previously
741 selected frame may be restored as the selected frame after return to
742 the command loop, because it still may have the window system's input
743 focus. On a text-only terminal, the next redisplay will display FRAME.
745 This function returns FRAME, or nil if FRAME has been deleted. */)
746 (frame)
747 Lisp_Object frame;
749 return do_switch_frame (frame, 1, 0);
753 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
754 doc: /* Handle a switch-frame event EVENT.
755 Switch-frame events are usually bound to this function.
756 A switch-frame event tells Emacs that the window manager has requested
757 that the user's events be directed to the frame mentioned in the event.
758 This function selects the selected window of the frame of EVENT.
760 If EVENT is frame object, handle it as if it were a switch-frame event
761 to that frame. */)
762 (event)
763 Lisp_Object event;
765 /* Preserve prefix arg that the command loop just cleared. */
766 current_kboard->Vprefix_arg = Vcurrent_prefix_arg;
767 call1 (Vrun_hooks, Qmouse_leave_buffer_hook);
768 return do_switch_frame (event, 0, 0);
771 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
772 doc: /* Return the frame that is now selected. */)
775 return selected_frame;
778 DEFUN ("window-frame", Fwindow_frame, Swindow_frame, 1, 1, 0,
779 doc: /* Return the frame object that window WINDOW is on. */)
780 (window)
781 Lisp_Object window;
783 CHECK_LIVE_WINDOW (window);
784 return XWINDOW (window)->frame;
787 DEFUN ("frame-first-window", Fframe_first_window, Sframe_first_window, 0, 1, 0,
788 doc: /* Returns the topmost, leftmost window of FRAME.
789 If omitted, FRAME defaults to the currently selected frame. */)
790 (frame)
791 Lisp_Object frame;
793 Lisp_Object w;
795 if (NILP (frame))
796 w = SELECTED_FRAME ()->root_window;
797 else
799 CHECK_LIVE_FRAME (frame);
800 w = XFRAME (frame)->root_window;
802 while (NILP (XWINDOW (w)->buffer))
804 if (! NILP (XWINDOW (w)->hchild))
805 w = XWINDOW (w)->hchild;
806 else if (! NILP (XWINDOW (w)->vchild))
807 w = XWINDOW (w)->vchild;
808 else
809 abort ();
811 return w;
814 DEFUN ("active-minibuffer-window", Factive_minibuffer_window,
815 Sactive_minibuffer_window, 0, 0, 0,
816 doc: /* Return the currently active minibuffer window, or nil if none. */)
819 return minibuf_level ? minibuf_window : Qnil;
822 DEFUN ("frame-root-window", Fframe_root_window, Sframe_root_window, 0, 1, 0,
823 doc: /* Returns the root-window of FRAME.
824 If omitted, FRAME defaults to the currently selected frame. */)
825 (frame)
826 Lisp_Object frame;
828 Lisp_Object window;
830 if (NILP (frame))
831 window = SELECTED_FRAME ()->root_window;
832 else
834 CHECK_LIVE_FRAME (frame);
835 window = XFRAME (frame)->root_window;
838 return window;
841 DEFUN ("frame-selected-window", Fframe_selected_window,
842 Sframe_selected_window, 0, 1, 0,
843 doc: /* Return the selected window of frame object FRAME.
844 If omitted, FRAME defaults to the currently selected frame. */)
845 (frame)
846 Lisp_Object frame;
848 Lisp_Object window;
850 if (NILP (frame))
851 window = SELECTED_FRAME ()->selected_window;
852 else
854 CHECK_LIVE_FRAME (frame);
855 window = XFRAME (frame)->selected_window;
858 return window;
861 DEFUN ("set-frame-selected-window", Fset_frame_selected_window,
862 Sset_frame_selected_window, 2, 2, 0,
863 doc: /* Set the selected window of frame object FRAME to WINDOW.
864 Return WINDOW.
865 If FRAME is nil, the selected frame is used.
866 If FRAME is the selected frame, this makes WINDOW the selected window. */)
867 (frame, window)
868 Lisp_Object frame, window;
870 if (NILP (frame))
871 frame = selected_frame;
873 CHECK_LIVE_FRAME (frame);
874 CHECK_LIVE_WINDOW (window);
876 if (! EQ (frame, WINDOW_FRAME (XWINDOW (window))))
877 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
879 if (EQ (frame, selected_frame))
880 return Fselect_window (window, Qnil);
882 return XFRAME (frame)->selected_window = window;
885 DEFUN ("frame-list", Fframe_list, Sframe_list,
886 0, 0, 0,
887 doc: /* Return a list of all frames. */)
890 Lisp_Object frames;
891 frames = Fcopy_sequence (Vframe_list);
892 #ifdef HAVE_WINDOW_SYSTEM
893 if (FRAMEP (tip_frame))
894 frames = Fdelq (tip_frame, frames);
895 #endif
896 return frames;
899 /* Return the next frame in the frame list after FRAME.
900 If MINIBUF is nil, exclude minibuffer-only frames.
901 If MINIBUF is a window, include only its own frame
902 and any frame now using that window as the minibuffer.
903 If MINIBUF is `visible', include all visible frames.
904 If MINIBUF is 0, include all visible and iconified frames.
905 Otherwise, include all frames. */
907 static Lisp_Object
908 next_frame (frame, minibuf)
909 Lisp_Object frame;
910 Lisp_Object minibuf;
912 Lisp_Object tail;
913 int passed = 0;
915 /* There must always be at least one frame in Vframe_list. */
916 if (! CONSP (Vframe_list))
917 abort ();
919 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
920 forever. Forestall that. */
921 CHECK_LIVE_FRAME (frame);
923 while (1)
924 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
926 Lisp_Object f;
928 f = XCAR (tail);
930 if (passed
931 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
933 /* Decide whether this frame is eligible to be returned. */
935 /* If we've looped all the way around without finding any
936 eligible frames, return the original frame. */
937 if (EQ (f, frame))
938 return f;
940 /* Let minibuf decide if this frame is acceptable. */
941 if (NILP (minibuf))
943 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
944 return f;
946 else if (EQ (minibuf, Qvisible))
948 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
949 if (FRAME_VISIBLE_P (XFRAME (f)))
950 return f;
952 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
954 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
955 if (FRAME_VISIBLE_P (XFRAME (f))
956 || FRAME_ICONIFIED_P (XFRAME (f)))
957 return f;
959 else if (WINDOWP (minibuf))
961 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
962 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
963 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
964 FRAME_FOCUS_FRAME (XFRAME (f))))
965 return f;
967 else
968 return f;
971 if (EQ (frame, f))
972 passed++;
976 /* Return the previous frame in the frame list before FRAME.
977 If MINIBUF is nil, exclude minibuffer-only frames.
978 If MINIBUF is a window, include only its own frame
979 and any frame now using that window as the minibuffer.
980 If MINIBUF is `visible', include all visible frames.
981 If MINIBUF is 0, include all visible and iconified frames.
982 Otherwise, include all frames. */
984 static Lisp_Object
985 prev_frame (frame, minibuf)
986 Lisp_Object frame;
987 Lisp_Object minibuf;
989 Lisp_Object tail;
990 Lisp_Object prev;
992 /* There must always be at least one frame in Vframe_list. */
993 if (! CONSP (Vframe_list))
994 abort ();
996 prev = Qnil;
997 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
999 Lisp_Object f;
1001 f = XCAR (tail);
1002 if (!FRAMEP (f))
1003 abort ();
1005 if (EQ (frame, f) && !NILP (prev))
1006 return prev;
1008 if (FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
1010 /* Decide whether this frame is eligible to be returned,
1011 according to minibuf. */
1012 if (NILP (minibuf))
1014 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
1015 prev = f;
1017 else if (WINDOWP (minibuf))
1019 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
1020 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
1021 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
1022 FRAME_FOCUS_FRAME (XFRAME (f))))
1023 prev = f;
1025 else if (EQ (minibuf, Qvisible))
1027 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1028 if (FRAME_VISIBLE_P (XFRAME (f)))
1029 prev = f;
1031 else if (XFASTINT (minibuf) == 0)
1033 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1034 if (FRAME_VISIBLE_P (XFRAME (f))
1035 || FRAME_ICONIFIED_P (XFRAME (f)))
1036 prev = f;
1038 else
1039 prev = f;
1043 /* We've scanned the entire list. */
1044 if (NILP (prev))
1045 /* We went through the whole frame list without finding a single
1046 acceptable frame. Return the original frame. */
1047 return frame;
1048 else
1049 /* There were no acceptable frames in the list before FRAME; otherwise,
1050 we would have returned directly from the loop. Since PREV is the last
1051 acceptable frame in the list, return it. */
1052 return prev;
1056 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1057 doc: /* Return the next frame in the frame list after FRAME.
1058 It considers only frames on the same terminal as FRAME.
1059 By default, skip minibuffer-only frames.
1060 If omitted, FRAME defaults to the selected frame.
1061 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1062 If MINIFRAME is a window, include only its own frame
1063 and any frame now using that window as the minibuffer.
1064 If MINIFRAME is `visible', include all visible frames.
1065 If MINIFRAME is 0, include all visible and iconified frames.
1066 Otherwise, include all frames. */)
1067 (frame, miniframe)
1068 Lisp_Object frame, miniframe;
1070 if (NILP (frame))
1071 frame = selected_frame;
1073 CHECK_LIVE_FRAME (frame);
1074 return next_frame (frame, miniframe);
1077 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1078 doc: /* Return the previous frame in the frame list before FRAME.
1079 It considers only frames on the same terminal as FRAME.
1080 By default, skip minibuffer-only frames.
1081 If omitted, FRAME defaults to the selected frame.
1082 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1083 If MINIFRAME is a window, include only its own frame
1084 and any frame now using that window as the minibuffer.
1085 If MINIFRAME is `visible', include all visible frames.
1086 If MINIFRAME is 0, include all visible and iconified frames.
1087 Otherwise, include all frames. */)
1088 (frame, miniframe)
1089 Lisp_Object frame, miniframe;
1091 if (NILP (frame))
1092 frame = selected_frame;
1093 CHECK_LIVE_FRAME (frame);
1094 return prev_frame (frame, miniframe);
1097 /* Return 1 if it is ok to delete frame F;
1098 0 if all frames aside from F are invisible.
1099 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1102 other_visible_frames (f)
1103 FRAME_PTR f;
1105 /* We know the selected frame is visible,
1106 so if F is some other frame, it can't be the sole visible one. */
1107 if (f == SELECTED_FRAME ())
1109 Lisp_Object frames;
1110 int count = 0;
1112 for (frames = Vframe_list;
1113 CONSP (frames);
1114 frames = XCDR (frames))
1116 Lisp_Object this;
1118 this = XCAR (frames);
1119 /* Verify that the frame's window still exists
1120 and we can still talk to it. And note any recent change
1121 in visibility. */
1122 #ifdef HAVE_WINDOW_SYSTEM
1123 if (FRAME_WINDOW_P (XFRAME (this)))
1125 x_sync (XFRAME (this));
1126 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1128 #endif
1130 if (FRAME_VISIBLE_P (XFRAME (this))
1131 || FRAME_ICONIFIED_P (XFRAME (this))
1132 /* Allow deleting the terminal frame when at least
1133 one X frame exists! */
1134 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1135 count++;
1137 return count > 1;
1139 return 1;
1142 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1143 doc: /* Delete FRAME, permanently eliminating it from use.
1144 If omitted, FRAME defaults to the selected frame.
1145 A frame may not be deleted if its minibuffer is used by other frames.
1146 Normally, you may not delete a frame if all other frames are invisible,
1147 but if the second optional argument FORCE is non-nil, you may do so.
1149 This function runs `delete-frame-functions' before actually deleting the
1150 frame, unless the frame is a tooltip.
1151 The functions are run with one arg, the frame to be deleted. */)
1152 (frame, force)
1153 Lisp_Object frame, force;
1155 struct frame *f;
1156 struct frame *sf = SELECTED_FRAME ();
1157 int minibuffer_selected;
1159 if (EQ (frame, Qnil))
1161 f = sf;
1162 XSETFRAME (frame, f);
1164 else
1166 CHECK_FRAME (frame);
1167 f = XFRAME (frame);
1170 if (! FRAME_LIVE_P (f))
1171 return Qnil;
1173 if (NILP (force) && !other_visible_frames (f)
1174 #ifdef MAC_OS8
1175 /* Terminal frame deleted before any other visible frames are
1176 created. */
1177 && strcmp (SDATA (f->name), "F1") != 0
1178 #endif
1180 error ("Attempt to delete the sole visible or iconified frame");
1182 #if 0
1183 /* This is a nice idea, but x_connection_closed needs to be able
1184 to delete the last frame, if it is gone. */
1185 if (NILP (XCDR (Vframe_list)))
1186 error ("Attempt to delete the only frame");
1187 #endif
1189 /* Does this frame have a minibuffer, and is it the surrogate
1190 minibuffer for any other frame? */
1191 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1193 Lisp_Object frames;
1195 for (frames = Vframe_list;
1196 CONSP (frames);
1197 frames = XCDR (frames))
1199 Lisp_Object this;
1200 this = XCAR (frames);
1202 if (! EQ (this, frame)
1203 && EQ (frame,
1204 WINDOW_FRAME (XWINDOW
1205 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1206 error ("Attempt to delete a surrogate minibuffer frame");
1210 /* Run `delete-frame-functions' unless frame is a tooltip. */
1211 if (!NILP (Vrun_hooks)
1212 && NILP (Fframe_parameter (frame, intern ("tooltip"))))
1214 Lisp_Object args[2];
1215 args[0] = intern ("delete-frame-functions");
1216 args[1] = frame;
1217 Frun_hook_with_args (2, args);
1220 minibuffer_selected = EQ (minibuf_window, selected_window);
1222 /* Don't let the frame remain selected. */
1223 if (f == sf)
1225 Lisp_Object tail, frame1;
1227 /* Look for another visible frame on the same terminal. */
1228 frame1 = next_frame (frame, Qvisible);
1230 /* If there is none, find *some* other frame. */
1231 if (NILP (frame1) || EQ (frame1, frame))
1233 FOR_EACH_FRAME (tail, frame1)
1235 if (! EQ (frame, frame1))
1236 break;
1240 do_switch_frame (frame1, 0, 1);
1241 sf = SELECTED_FRAME ();
1244 /* Don't allow minibuf_window to remain on a deleted frame. */
1245 if (EQ (f->minibuffer_window, minibuf_window))
1247 Fset_window_buffer (sf->minibuffer_window,
1248 XWINDOW (minibuf_window)->buffer, Qnil);
1249 minibuf_window = sf->minibuffer_window;
1251 /* If the dying minibuffer window was selected,
1252 select the new one. */
1253 if (minibuffer_selected)
1254 Fselect_window (minibuf_window, Qnil);
1257 /* Don't let echo_area_window to remain on a deleted frame. */
1258 if (EQ (f->minibuffer_window, echo_area_window))
1259 echo_area_window = sf->minibuffer_window;
1261 /* Clear any X selections for this frame. */
1262 #ifdef HAVE_X_WINDOWS
1263 if (FRAME_X_P (f))
1264 x_clear_frame_selections (f);
1265 #endif
1266 #ifdef MAC_OS
1267 if (FRAME_MAC_P (f))
1268 x_clear_frame_selections (f);
1269 #endif
1271 /* Free glyphs.
1272 This function must be called before the window tree of the
1273 frame is deleted because windows contain dynamically allocated
1274 memory. */
1275 free_glyphs (f);
1277 /* Mark all the windows that used to be on FRAME as deleted, and then
1278 remove the reference to them. */
1279 delete_all_subwindows (XWINDOW (f->root_window));
1280 f->root_window = Qnil;
1282 Vframe_list = Fdelq (frame, Vframe_list);
1283 FRAME_SET_VISIBLE (f, 0);
1285 if (f->namebuf)
1286 xfree (f->namebuf);
1287 if (f->decode_mode_spec_buffer)
1288 xfree (f->decode_mode_spec_buffer);
1289 if (FRAME_INSERT_COST (f))
1290 xfree (FRAME_INSERT_COST (f));
1291 if (FRAME_DELETEN_COST (f))
1292 xfree (FRAME_DELETEN_COST (f));
1293 if (FRAME_INSERTN_COST (f))
1294 xfree (FRAME_INSERTN_COST (f));
1295 if (FRAME_DELETE_COST (f))
1296 xfree (FRAME_DELETE_COST (f));
1297 if (FRAME_MESSAGE_BUF (f))
1298 xfree (FRAME_MESSAGE_BUF (f));
1300 /* Since some events are handled at the interrupt level, we may get
1301 an event for f at any time; if we zero out the frame's display
1302 now, then we may trip up the event-handling code. Instead, we'll
1303 promise that the display of the frame must be valid until we have
1304 called the window-system-dependent frame destruction routine. */
1306 /* I think this should be done with a hook. */
1307 #ifdef HAVE_WINDOW_SYSTEM
1308 if (FRAME_WINDOW_P (f))
1309 x_destroy_window (f);
1310 #endif
1312 f->output_data.nothing = 0;
1314 /* If we've deleted the last_nonminibuf_frame, then try to find
1315 another one. */
1316 if (f == last_nonminibuf_frame)
1318 Lisp_Object frames;
1320 last_nonminibuf_frame = 0;
1322 for (frames = Vframe_list;
1323 CONSP (frames);
1324 frames = XCDR (frames))
1326 f = XFRAME (XCAR (frames));
1327 if (!FRAME_MINIBUF_ONLY_P (f))
1329 last_nonminibuf_frame = f;
1330 break;
1335 /* If there's no other frame on the same kboard, get out of
1336 single-kboard state if we're in it for this kboard. */
1338 Lisp_Object frames;
1339 /* Some frame we found on the same kboard, or nil if there are none. */
1340 Lisp_Object frame_on_same_kboard;
1342 frame_on_same_kboard = Qnil;
1344 for (frames = Vframe_list;
1345 CONSP (frames);
1346 frames = XCDR (frames))
1348 Lisp_Object this;
1349 struct frame *f1;
1351 this = XCAR (frames);
1352 if (!FRAMEP (this))
1353 abort ();
1354 f1 = XFRAME (this);
1356 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1357 frame_on_same_kboard = this;
1360 if (NILP (frame_on_same_kboard))
1361 not_single_kboard_state (FRAME_KBOARD (f));
1365 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1366 find another one. Prefer minibuffer-only frames, but also notice
1367 frames with other windows. */
1368 if (EQ (frame, FRAME_KBOARD (f)->Vdefault_minibuffer_frame))
1370 Lisp_Object frames;
1372 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1373 Lisp_Object frame_with_minibuf;
1374 /* Some frame we found on the same kboard, or nil if there are none. */
1375 Lisp_Object frame_on_same_kboard;
1377 frame_on_same_kboard = Qnil;
1378 frame_with_minibuf = Qnil;
1380 for (frames = Vframe_list;
1381 CONSP (frames);
1382 frames = XCDR (frames))
1384 Lisp_Object this;
1385 struct frame *f1;
1387 this = XCAR (frames);
1388 if (!FRAMEP (this))
1389 abort ();
1390 f1 = XFRAME (this);
1392 /* Consider only frames on the same kboard
1393 and only those with minibuffers. */
1394 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1)
1395 && FRAME_HAS_MINIBUF_P (f1))
1397 frame_with_minibuf = this;
1398 if (FRAME_MINIBUF_ONLY_P (f1))
1399 break;
1402 if (FRAME_KBOARD (f) == FRAME_KBOARD (f1))
1403 frame_on_same_kboard = this;
1406 if (!NILP (frame_on_same_kboard))
1408 /* We know that there must be some frame with a minibuffer out
1409 there. If this were not true, all of the frames present
1410 would have to be minibufferless, which implies that at some
1411 point their minibuffer frames must have been deleted, but
1412 that is prohibited at the top; you can't delete surrogate
1413 minibuffer frames. */
1414 if (NILP (frame_with_minibuf))
1415 abort ();
1417 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = frame_with_minibuf;
1419 else
1420 /* No frames left on this kboard--say no minibuffer either. */
1421 FRAME_KBOARD (f)->Vdefault_minibuffer_frame = Qnil;
1424 /* Cause frame titles to update--necessary if we now have just one frame. */
1425 update_mode_lines = 1;
1427 return Qnil;
1430 /* Return mouse position in character cell units. */
1432 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1433 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1434 The position is given in character cells, where (0, 0) is the
1435 upper-left corner of the frame, X is the horizontal offset, and Y is
1436 the vertical offset.
1437 If Emacs is running on a mouseless terminal or hasn't been programmed
1438 to read the mouse position, it returns the selected frame for FRAME
1439 and nil for X and Y.
1440 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1441 passing the normal return value to that function as an argument,
1442 and returns whatever that function returns. */)
1445 FRAME_PTR f;
1446 Lisp_Object lispy_dummy;
1447 enum scroll_bar_part party_dummy;
1448 Lisp_Object x, y, retval;
1449 int col, row;
1450 unsigned long long_dummy;
1451 struct gcpro gcpro1;
1453 f = SELECTED_FRAME ();
1454 x = y = Qnil;
1456 #ifdef HAVE_MOUSE
1457 /* It's okay for the hook to refrain from storing anything. */
1458 if (mouse_position_hook)
1459 (*mouse_position_hook) (&f, -1,
1460 &lispy_dummy, &party_dummy,
1461 &x, &y,
1462 &long_dummy);
1463 if (! NILP (x))
1465 col = XINT (x);
1466 row = XINT (y);
1467 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1468 XSETINT (x, col);
1469 XSETINT (y, row);
1471 #endif
1472 XSETFRAME (lispy_dummy, f);
1473 retval = Fcons (lispy_dummy, Fcons (x, y));
1474 GCPRO1 (retval);
1475 if (!NILP (Vmouse_position_function))
1476 retval = call1 (Vmouse_position_function, retval);
1477 RETURN_UNGCPRO (retval);
1480 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1481 Smouse_pixel_position, 0, 0, 0,
1482 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1483 The position is given in pixel units, where (0, 0) is the
1484 upper-left corner of the frame, X is the horizontal offset, and Y is
1485 the vertical offset.
1486 If Emacs is running on a mouseless terminal or hasn't been programmed
1487 to read the mouse position, it returns the selected frame for FRAME
1488 and nil for X and Y. */)
1491 FRAME_PTR f;
1492 Lisp_Object lispy_dummy;
1493 enum scroll_bar_part party_dummy;
1494 Lisp_Object x, y;
1495 unsigned long long_dummy;
1497 f = SELECTED_FRAME ();
1498 x = y = Qnil;
1500 #ifdef HAVE_MOUSE
1501 /* It's okay for the hook to refrain from storing anything. */
1502 if (mouse_position_hook)
1503 (*mouse_position_hook) (&f, -1,
1504 &lispy_dummy, &party_dummy,
1505 &x, &y,
1506 &long_dummy);
1507 #endif
1508 XSETFRAME (lispy_dummy, f);
1509 return Fcons (lispy_dummy, Fcons (x, y));
1512 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1513 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1514 Coordinates are relative to the frame, not a window,
1515 so the coordinates of the top left character in the frame
1516 may be nonzero due to left-hand scroll bars or the menu bar.
1518 The position is given in character cells, where (0, 0) is the
1519 upper-left corner of the frame, X is the horizontal offset, and Y is
1520 the vertical offset.
1522 This function is a no-op for an X frame that is not visible.
1523 If you have just created a frame, you must wait for it to become visible
1524 before calling this function on it, like this.
1525 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1526 (frame, x, y)
1527 Lisp_Object frame, x, y;
1529 CHECK_LIVE_FRAME (frame);
1530 CHECK_NUMBER (x);
1531 CHECK_NUMBER (y);
1533 /* I think this should be done with a hook. */
1534 #ifdef HAVE_WINDOW_SYSTEM
1535 if (FRAME_WINDOW_P (XFRAME (frame)))
1536 /* Warping the mouse will cause enternotify and focus events. */
1537 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1538 #else
1539 #if defined (MSDOS) && defined (HAVE_MOUSE)
1540 if (FRAME_MSDOS_P (XFRAME (frame)))
1542 Fselect_frame (frame);
1543 mouse_moveto (XINT (x), XINT (y));
1545 #endif
1546 #endif
1548 return Qnil;
1551 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1552 Sset_mouse_pixel_position, 3, 3, 0,
1553 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1554 The position is given in pixels, where (0, 0) is the upper-left corner
1555 of the frame, X is the horizontal offset, and Y is the vertical offset.
1557 Note, this is a no-op for an X frame that is not visible.
1558 If you have just created a frame, you must wait for it to become visible
1559 before calling this function on it, like this.
1560 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1561 (frame, x, y)
1562 Lisp_Object frame, x, y;
1564 CHECK_LIVE_FRAME (frame);
1565 CHECK_NUMBER (x);
1566 CHECK_NUMBER (y);
1568 /* I think this should be done with a hook. */
1569 #ifdef HAVE_WINDOW_SYSTEM
1570 if (FRAME_WINDOW_P (XFRAME (frame)))
1571 /* Warping the mouse will cause enternotify and focus events. */
1572 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1573 #else
1574 #if defined (MSDOS) && defined (HAVE_MOUSE)
1575 if (FRAME_MSDOS_P (XFRAME (frame)))
1577 Fselect_frame (frame);
1578 mouse_moveto (XINT (x), XINT (y));
1580 #endif
1581 #endif
1583 return Qnil;
1586 static void make_frame_visible_1 P_ ((Lisp_Object));
1588 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1589 0, 1, "",
1590 doc: /* Make the frame FRAME visible (assuming it is an X window).
1591 If omitted, FRAME defaults to the currently selected frame. */)
1592 (frame)
1593 Lisp_Object frame;
1595 if (NILP (frame))
1596 frame = selected_frame;
1598 CHECK_LIVE_FRAME (frame);
1600 /* I think this should be done with a hook. */
1601 #ifdef HAVE_WINDOW_SYSTEM
1602 if (FRAME_WINDOW_P (XFRAME (frame)))
1604 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1605 x_make_frame_visible (XFRAME (frame));
1607 #endif
1609 make_frame_visible_1 (XFRAME (frame)->root_window);
1611 /* Make menu bar update for the Buffers and Frames menus. */
1612 windows_or_buffers_changed++;
1614 return frame;
1617 /* Update the display_time slot of the buffers shown in WINDOW
1618 and all its descendents. */
1620 static void
1621 make_frame_visible_1 (window)
1622 Lisp_Object window;
1624 struct window *w;
1626 for (;!NILP (window); window = w->next)
1628 w = XWINDOW (window);
1630 if (!NILP (w->buffer))
1631 XBUFFER (w->buffer)->display_time = Fcurrent_time ();
1633 if (!NILP (w->vchild))
1634 make_frame_visible_1 (w->vchild);
1635 if (!NILP (w->hchild))
1636 make_frame_visible_1 (w->hchild);
1640 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1641 0, 2, "",
1642 doc: /* Make the frame FRAME invisible (assuming it is an X window).
1643 If omitted, FRAME defaults to the currently selected frame.
1644 Normally you may not make FRAME invisible if all other frames are invisible,
1645 but if the second optional argument FORCE is non-nil, you may do so. */)
1646 (frame, force)
1647 Lisp_Object frame, force;
1649 if (NILP (frame))
1650 frame = selected_frame;
1652 CHECK_LIVE_FRAME (frame);
1654 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1655 error ("Attempt to make invisible the sole visible or iconified frame");
1657 #if 0 /* This isn't logically necessary, and it can do GC. */
1658 /* Don't let the frame remain selected. */
1659 if (EQ (frame, selected_frame))
1660 do_switch_frame (next_frame (frame, Qt), 0, 0)
1661 #endif
1663 /* Don't allow minibuf_window to remain on a deleted frame. */
1664 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1666 struct frame *sf = XFRAME (selected_frame);
1667 Fset_window_buffer (sf->minibuffer_window,
1668 XWINDOW (minibuf_window)->buffer, Qnil);
1669 minibuf_window = sf->minibuffer_window;
1672 /* I think this should be done with a hook. */
1673 #ifdef HAVE_WINDOW_SYSTEM
1674 if (FRAME_WINDOW_P (XFRAME (frame)))
1675 x_make_frame_invisible (XFRAME (frame));
1676 #endif
1678 /* Make menu bar update for the Buffers and Frames menus. */
1679 windows_or_buffers_changed++;
1681 return Qnil;
1684 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1685 0, 1, "",
1686 doc: /* Make the frame FRAME into an icon.
1687 If omitted, FRAME defaults to the currently selected frame. */)
1688 (frame)
1689 Lisp_Object frame;
1691 if (NILP (frame))
1692 frame = selected_frame;
1694 CHECK_LIVE_FRAME (frame);
1696 #if 0 /* This isn't logically necessary, and it can do GC. */
1697 /* Don't let the frame remain selected. */
1698 if (EQ (frame, selected_frame))
1699 Fhandle_switch_frame (next_frame (frame, Qt));
1700 #endif
1702 /* Don't allow minibuf_window to remain on a deleted frame. */
1703 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1705 struct frame *sf = XFRAME (selected_frame);
1706 Fset_window_buffer (sf->minibuffer_window,
1707 XWINDOW (minibuf_window)->buffer, Qnil);
1708 minibuf_window = sf->minibuffer_window;
1711 /* I think this should be done with a hook. */
1712 #ifdef HAVE_WINDOW_SYSTEM
1713 if (FRAME_WINDOW_P (XFRAME (frame)))
1714 x_iconify_frame (XFRAME (frame));
1715 #endif
1717 /* Make menu bar update for the Buffers and Frames menus. */
1718 windows_or_buffers_changed++;
1720 return Qnil;
1723 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1724 1, 1, 0,
1725 doc: /* Return t if FRAME is now \"visible\" (actually in use for display).
1726 A frame that is not \"visible\" is not updated and, if it works through
1727 a window system, it may not show at all.
1728 Return the symbol `icon' if frame is visible only as an icon.
1730 On a text-only terminal, all frames are considered visible, whether
1731 they are currently being displayed or not, and this function returns t
1732 for all frames. */)
1733 (frame)
1734 Lisp_Object frame;
1736 CHECK_LIVE_FRAME (frame);
1738 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1740 if (FRAME_VISIBLE_P (XFRAME (frame)))
1741 return Qt;
1742 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1743 return Qicon;
1744 return Qnil;
1747 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1748 0, 0, 0,
1749 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1752 Lisp_Object tail, frame;
1753 struct frame *f;
1754 Lisp_Object value;
1756 value = Qnil;
1757 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1759 frame = XCAR (tail);
1760 if (!FRAMEP (frame))
1761 continue;
1762 f = XFRAME (frame);
1763 if (FRAME_VISIBLE_P (f))
1764 value = Fcons (frame, value);
1766 return value;
1770 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1771 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1772 If FRAME is invisible or iconified, make it visible.
1773 If you don't specify a frame, the selected frame is used.
1774 If Emacs is displaying on an ordinary terminal or some other device which
1775 doesn't support multiple overlapping frames, this function does nothing. */)
1776 (frame)
1777 Lisp_Object frame;
1779 if (NILP (frame))
1780 frame = selected_frame;
1782 CHECK_LIVE_FRAME (frame);
1784 /* Do like the documentation says. */
1785 Fmake_frame_visible (frame);
1787 if (frame_raise_lower_hook)
1788 (*frame_raise_lower_hook) (XFRAME (frame), 1);
1790 return Qnil;
1793 /* Should we have a corresponding function called Flower_Power? */
1794 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1795 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1796 If you don't specify a frame, the selected frame is used.
1797 If Emacs is displaying on an ordinary terminal or some other device which
1798 doesn't support multiple overlapping frames, this function does nothing. */)
1799 (frame)
1800 Lisp_Object frame;
1802 if (NILP (frame))
1803 frame = selected_frame;
1805 CHECK_LIVE_FRAME (frame);
1807 if (frame_raise_lower_hook)
1808 (*frame_raise_lower_hook) (XFRAME (frame), 0);
1810 return Qnil;
1814 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1815 1, 2, 0,
1816 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1817 In other words, switch-frame events caused by events in FRAME will
1818 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1819 FOCUS-FRAME after reading an event typed at FRAME.
1821 If FOCUS-FRAME is omitted or nil, any existing redirection is
1822 cancelled, and the frame again receives its own keystrokes.
1824 Focus redirection is useful for temporarily redirecting keystrokes to
1825 a surrogate minibuffer frame when a frame doesn't have its own
1826 minibuffer window.
1828 A frame's focus redirection can be changed by `select-frame'. If frame
1829 FOO is selected, and then a different frame BAR is selected, any
1830 frames redirecting their focus to FOO are shifted to redirect their
1831 focus to BAR. This allows focus redirection to work properly when the
1832 user switches from one frame to another using `select-window'.
1834 This means that a frame whose focus is redirected to itself is treated
1835 differently from a frame whose focus is redirected to nil; the former
1836 is affected by `select-frame', while the latter is not.
1838 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1839 (frame, focus_frame)
1840 Lisp_Object frame, focus_frame;
1842 /* Note that we don't check for a live frame here. It's reasonable
1843 to redirect the focus of a frame you're about to delete, if you
1844 know what other frame should receive those keystrokes. */
1845 CHECK_FRAME (frame);
1847 if (! NILP (focus_frame))
1848 CHECK_LIVE_FRAME (focus_frame);
1850 XFRAME (frame)->focus_frame = focus_frame;
1852 if (frame_rehighlight_hook)
1853 (*frame_rehighlight_hook) (XFRAME (frame));
1855 return Qnil;
1859 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1860 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1861 This returns nil if FRAME's focus is not redirected.
1862 See `redirect-frame-focus'. */)
1863 (frame)
1864 Lisp_Object frame;
1866 CHECK_LIVE_FRAME (frame);
1868 return FRAME_FOCUS_FRAME (XFRAME (frame));
1873 /* Return the value of frame parameter PROP in frame FRAME. */
1875 Lisp_Object
1876 get_frame_param (frame, prop)
1877 register struct frame *frame;
1878 Lisp_Object prop;
1880 register Lisp_Object tem;
1882 tem = Fassq (prop, frame->param_alist);
1883 if (EQ (tem, Qnil))
1884 return tem;
1885 return Fcdr (tem);
1888 /* Return the buffer-predicate of the selected frame. */
1890 Lisp_Object
1891 frame_buffer_predicate (frame)
1892 Lisp_Object frame;
1894 return XFRAME (frame)->buffer_predicate;
1897 /* Return the buffer-list of the selected frame. */
1899 Lisp_Object
1900 frame_buffer_list (frame)
1901 Lisp_Object frame;
1903 return XFRAME (frame)->buffer_list;
1906 /* Set the buffer-list of the selected frame. */
1908 void
1909 set_frame_buffer_list (frame, list)
1910 Lisp_Object frame, list;
1912 XFRAME (frame)->buffer_list = list;
1915 /* Discard BUFFER from the buffer-list of each frame. */
1917 void
1918 frames_discard_buffer (buffer)
1919 Lisp_Object buffer;
1921 Lisp_Object frame, tail;
1923 FOR_EACH_FRAME (tail, frame)
1925 XFRAME (frame)->buffer_list
1926 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1930 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1931 If the alist already has an element for PROP, we change it. */
1933 void
1934 store_in_alist (alistptr, prop, val)
1935 Lisp_Object *alistptr, val;
1936 Lisp_Object prop;
1938 register Lisp_Object tem;
1940 tem = Fassq (prop, *alistptr);
1941 if (EQ (tem, Qnil))
1942 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1943 else
1944 Fsetcdr (tem, val);
1947 static int
1948 frame_name_fnn_p (str, len)
1949 char *str;
1950 int len;
1952 if (len > 1 && str[0] == 'F')
1954 char *end_ptr;
1956 strtol (str + 1, &end_ptr, 10);
1958 if (end_ptr == str + len)
1959 return 1;
1961 return 0;
1964 /* Set the name of the terminal frame. Also used by MSDOS frames.
1965 Modeled after x_set_name which is used for WINDOW frames. */
1967 static void
1968 set_term_frame_name (f, name)
1969 struct frame *f;
1970 Lisp_Object name;
1972 f->explicit_name = ! NILP (name);
1974 /* If NAME is nil, set the name to F<num>. */
1975 if (NILP (name))
1977 char namebuf[20];
1979 /* Check for no change needed in this very common case
1980 before we do any consing. */
1981 if (frame_name_fnn_p (SDATA (f->name),
1982 SBYTES (f->name)))
1983 return;
1985 terminal_frame_count++;
1986 sprintf (namebuf, "F%d", terminal_frame_count);
1987 name = build_string (namebuf);
1989 else
1991 CHECK_STRING (name);
1993 /* Don't change the name if it's already NAME. */
1994 if (! NILP (Fstring_equal (name, f->name)))
1995 return;
1997 /* Don't allow the user to set the frame name to F<num>, so it
1998 doesn't clash with the names we generate for terminal frames. */
1999 if (frame_name_fnn_p (SDATA (name), SBYTES (name)))
2000 error ("Frame names of the form F<num> are usurped by Emacs");
2003 f->name = name;
2004 update_mode_lines = 1;
2007 void
2008 store_frame_param (f, prop, val)
2009 struct frame *f;
2010 Lisp_Object prop, val;
2012 register Lisp_Object old_alist_elt;
2014 /* The buffer-alist parameter is stored in a special place and is
2015 not in the alist. */
2016 if (EQ (prop, Qbuffer_list))
2018 f->buffer_list = val;
2019 return;
2022 /* If PROP is a symbol which is supposed to have frame-local values,
2023 and it is set up based on this frame, switch to the global
2024 binding. That way, we can create or alter the frame-local binding
2025 without messing up the symbol's status. */
2026 if (SYMBOLP (prop))
2028 Lisp_Object valcontents;
2029 valcontents = SYMBOL_VALUE (prop);
2030 if ((BUFFER_LOCAL_VALUEP (valcontents)
2031 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
2032 && XBUFFER_LOCAL_VALUE (valcontents)->check_frame
2033 && XFRAME (XBUFFER_LOCAL_VALUE (valcontents)->frame) == f)
2034 swap_in_global_binding (prop);
2037 #ifndef WINDOWSNT
2038 /* The tty color mode needs to be set before the frame's parameter
2039 alist is updated with the new value, because set_tty_color_mode
2040 wants to look at the old mode. */
2041 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode))
2042 set_tty_color_mode (f, val);
2043 #endif
2045 /* Update the frame parameter alist. */
2046 old_alist_elt = Fassq (prop, f->param_alist);
2047 if (EQ (old_alist_elt, Qnil))
2048 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2049 else
2050 Fsetcdr (old_alist_elt, val);
2052 /* Update some other special parameters in their special places
2053 in addition to the alist. */
2055 if (EQ (prop, Qbuffer_predicate))
2056 f->buffer_predicate = val;
2058 if (! FRAME_WINDOW_P (f))
2060 if (EQ (prop, Qmenu_bar_lines))
2061 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2062 else if (EQ (prop, Qname))
2063 set_term_frame_name (f, val);
2066 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2068 if (! MINI_WINDOW_P (XWINDOW (val)))
2069 error ("Surrogate minibuffer windows must be minibuffer windows");
2071 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2072 && !EQ (val, f->minibuffer_window))
2073 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2075 /* Install the chosen minibuffer window, with proper buffer. */
2076 f->minibuffer_window = val;
2080 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2081 doc: /* Return the parameters-alist of frame FRAME.
2082 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2083 The meaningful PARMs depend on the kind of frame.
2084 If FRAME is omitted, return information on the currently selected frame. */)
2085 (frame)
2086 Lisp_Object frame;
2088 Lisp_Object alist;
2089 FRAME_PTR f;
2090 int height, width;
2091 struct gcpro gcpro1;
2093 if (NILP (frame))
2094 frame = selected_frame;
2096 CHECK_FRAME (frame);
2097 f = XFRAME (frame);
2099 if (!FRAME_LIVE_P (f))
2100 return Qnil;
2102 alist = Fcopy_alist (f->param_alist);
2103 GCPRO1 (alist);
2105 if (!FRAME_WINDOW_P (f))
2107 int fg = FRAME_FOREGROUND_PIXEL (f);
2108 int bg = FRAME_BACKGROUND_PIXEL (f);
2109 Lisp_Object elt;
2111 /* If the frame's parameter alist says the colors are
2112 unspecified and reversed, take the frame's background pixel
2113 for foreground and vice versa. */
2114 elt = Fassq (Qforeground_color, alist);
2115 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2117 if (strncmp (SDATA (XCDR (elt)),
2118 unspecified_bg,
2119 SCHARS (XCDR (elt))) == 0)
2120 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2121 else if (strncmp (SDATA (XCDR (elt)),
2122 unspecified_fg,
2123 SCHARS (XCDR (elt))) == 0)
2124 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2126 else
2127 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2128 elt = Fassq (Qbackground_color, alist);
2129 if (!NILP (elt) && CONSP (elt) && STRINGP (XCDR (elt)))
2131 if (strncmp (SDATA (XCDR (elt)),
2132 unspecified_fg,
2133 SCHARS (XCDR (elt))) == 0)
2134 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2135 else if (strncmp (SDATA (XCDR (elt)),
2136 unspecified_bg,
2137 SCHARS (XCDR (elt))) == 0)
2138 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2140 else
2141 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2142 store_in_alist (&alist, intern ("font"),
2143 build_string (FRAME_MSDOS_P (f)
2144 ? "ms-dos"
2145 : FRAME_W32_P (f) ? "w32term"
2146 :"tty"));
2148 store_in_alist (&alist, Qname, f->name);
2149 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2150 store_in_alist (&alist, Qheight, make_number (height));
2151 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2152 store_in_alist (&alist, Qwidth, make_number (width));
2153 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2154 store_in_alist (&alist, Qminibuffer,
2155 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2156 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2157 : FRAME_MINIBUF_WINDOW (f)));
2158 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2159 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2161 /* I think this should be done with a hook. */
2162 #ifdef HAVE_WINDOW_SYSTEM
2163 if (FRAME_WINDOW_P (f))
2164 x_report_frame_params (f, &alist);
2165 else
2166 #endif
2168 /* This ought to be correct in f->param_alist for an X frame. */
2169 Lisp_Object lines;
2170 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2171 store_in_alist (&alist, Qmenu_bar_lines, lines);
2174 UNGCPRO;
2175 return alist;
2179 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2180 doc: /* Return FRAME's value for parameter PARAMETER.
2181 If FRAME is nil, describe the currently selected frame. */)
2182 (frame, parameter)
2183 Lisp_Object frame, parameter;
2185 struct frame *f;
2186 Lisp_Object value;
2188 if (NILP (frame))
2189 frame = selected_frame;
2190 else
2191 CHECK_FRAME (frame);
2192 CHECK_SYMBOL (parameter);
2194 f = XFRAME (frame);
2195 value = Qnil;
2197 if (FRAME_LIVE_P (f))
2199 /* Avoid consing in frequent cases. */
2200 if (EQ (parameter, Qname))
2201 value = f->name;
2202 #ifdef HAVE_X_WINDOWS
2203 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2204 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2205 #endif /* HAVE_X_WINDOWS */
2206 else if (EQ (parameter, Qbackground_color)
2207 || EQ (parameter, Qforeground_color))
2209 value = Fassq (parameter, f->param_alist);
2210 if (CONSP (value))
2212 value = XCDR (value);
2213 /* Fframe_parameters puts the actual fg/bg color names,
2214 even if f->param_alist says otherwise. This is
2215 important when param_alist's notion of colors is
2216 "unspecified". We need to do the same here. */
2217 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2219 const char *color_name;
2220 EMACS_INT csz;
2222 if (EQ (parameter, Qbackground_color))
2224 color_name = SDATA (value);
2225 csz = SCHARS (value);
2226 if (strncmp (color_name, unspecified_bg, csz) == 0)
2227 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2228 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2229 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2231 else if (EQ (parameter, Qforeground_color))
2233 color_name = SDATA (value);
2234 csz = SCHARS (value);
2235 if (strncmp (color_name, unspecified_fg, csz) == 0)
2236 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2237 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2238 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2242 else
2243 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2245 else if (EQ (parameter, Qdisplay_type)
2246 || EQ (parameter, Qbackground_mode))
2247 value = Fcdr (Fassq (parameter, f->param_alist));
2248 else
2249 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2252 return value;
2256 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2257 Smodify_frame_parameters, 2, 2, 0,
2258 doc: /* Modify the parameters of frame FRAME according to ALIST.
2259 If FRAME is nil, it defaults to the selected frame.
2260 ALIST is an alist of parameters to change and their new values.
2261 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2262 The meaningful PARMs depend on the kind of frame.
2263 Undefined PARMs are ignored, but stored in the frame's parameter list
2264 so that `frame-parameters' will return them.
2266 The value of frame parameter FOO can also be accessed
2267 as a frame-local binding for the variable FOO, if you have
2268 enabled such bindings for that variable with `make-variable-frame-local'. */)
2269 (frame, alist)
2270 Lisp_Object frame, alist;
2272 FRAME_PTR f;
2273 register Lisp_Object tail, prop, val;
2275 if (EQ (frame, Qnil))
2276 frame = selected_frame;
2277 CHECK_LIVE_FRAME (frame);
2278 f = XFRAME (frame);
2280 /* I think this should be done with a hook. */
2281 #ifdef HAVE_WINDOW_SYSTEM
2282 if (FRAME_WINDOW_P (f))
2283 x_set_frame_parameters (f, alist);
2284 else
2285 #endif
2286 #ifdef MSDOS
2287 if (FRAME_MSDOS_P (f))
2288 IT_set_frame_parameters (f, alist);
2289 else
2290 #endif
2293 int length = XINT (Flength (alist));
2294 int i;
2295 Lisp_Object *parms
2296 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2297 Lisp_Object *values
2298 = (Lisp_Object *) alloca (length * sizeof (Lisp_Object));
2300 /* Extract parm names and values into those vectors. */
2302 i = 0;
2303 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2305 Lisp_Object elt;
2307 elt = Fcar (tail);
2308 parms[i] = Fcar (elt);
2309 values[i] = Fcdr (elt);
2310 i++;
2313 /* Now process them in reverse of specified order. */
2314 for (i--; i >= 0; i--)
2316 prop = parms[i];
2317 val = values[i];
2318 store_frame_param (f, prop, val);
2320 /* Changing the background color might change the background
2321 mode, so that we have to load new defface specs.
2322 Call frame-set-background-mode to do that. */
2323 if (EQ (prop, Qbackground_color))
2324 call1 (Qframe_set_background_mode, frame);
2328 return Qnil;
2331 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2332 0, 1, 0,
2333 doc: /* Height in pixels of a line in the font in frame FRAME.
2334 If FRAME is omitted, the selected frame is used.
2335 For a terminal frame, the value is always 1. */)
2336 (frame)
2337 Lisp_Object frame;
2339 struct frame *f;
2341 if (NILP (frame))
2342 frame = selected_frame;
2343 CHECK_FRAME (frame);
2344 f = XFRAME (frame);
2346 #ifdef HAVE_WINDOW_SYSTEM
2347 if (FRAME_WINDOW_P (f))
2348 return make_number (x_char_height (f));
2349 else
2350 #endif
2351 return make_number (1);
2355 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2356 0, 1, 0,
2357 doc: /* Width in pixels of characters in the font in frame FRAME.
2358 If FRAME is omitted, the selected frame is used.
2359 On a graphical screen, the width is the standard width of the default font.
2360 For a terminal screen, the value is always 1. */)
2361 (frame)
2362 Lisp_Object frame;
2364 struct frame *f;
2366 if (NILP (frame))
2367 frame = selected_frame;
2368 CHECK_FRAME (frame);
2369 f = XFRAME (frame);
2371 #ifdef HAVE_WINDOW_SYSTEM
2372 if (FRAME_WINDOW_P (f))
2373 return make_number (x_char_width (f));
2374 else
2375 #endif
2376 return make_number (1);
2379 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2380 Sframe_pixel_height, 0, 1, 0,
2381 doc: /* Return a FRAME's height in pixels.
2382 This counts only the height available for text lines,
2383 not menu bars on window-system Emacs frames.
2384 For a terminal frame, the result really gives the height in characters.
2385 If FRAME is omitted, the selected frame is used. */)
2386 (frame)
2387 Lisp_Object frame;
2389 struct frame *f;
2391 if (NILP (frame))
2392 frame = selected_frame;
2393 CHECK_FRAME (frame);
2394 f = XFRAME (frame);
2396 #ifdef HAVE_WINDOW_SYSTEM
2397 if (FRAME_WINDOW_P (f))
2398 return make_number (x_pixel_height (f));
2399 else
2400 #endif
2401 return make_number (FRAME_LINES (f));
2404 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2405 Sframe_pixel_width, 0, 1, 0,
2406 doc: /* Return FRAME's width in pixels.
2407 For a terminal frame, the result really gives the width in characters.
2408 If FRAME is omitted, the selected frame is used. */)
2409 (frame)
2410 Lisp_Object frame;
2412 struct frame *f;
2414 if (NILP (frame))
2415 frame = selected_frame;
2416 CHECK_FRAME (frame);
2417 f = XFRAME (frame);
2419 #ifdef HAVE_WINDOW_SYSTEM
2420 if (FRAME_WINDOW_P (f))
2421 return make_number (x_pixel_width (f));
2422 else
2423 #endif
2424 return make_number (FRAME_COLS (f));
2427 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2428 doc: /* Specify that the frame FRAME has LINES lines.
2429 Optional third arg non-nil means that redisplay should use LINES lines
2430 but that the idea of the actual height of the frame should not be changed. */)
2431 (frame, lines, pretend)
2432 Lisp_Object frame, lines, pretend;
2434 register struct frame *f;
2436 CHECK_NUMBER (lines);
2437 if (NILP (frame))
2438 frame = selected_frame;
2439 CHECK_LIVE_FRAME (frame);
2440 f = XFRAME (frame);
2442 /* I think this should be done with a hook. */
2443 #ifdef HAVE_WINDOW_SYSTEM
2444 if (FRAME_WINDOW_P (f))
2446 if (XINT (lines) != FRAME_LINES (f))
2447 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2448 do_pending_window_change (0);
2450 else
2451 #endif
2452 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2453 return Qnil;
2456 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2457 doc: /* Specify that the frame FRAME has COLS columns.
2458 Optional third arg non-nil means that redisplay should use COLS columns
2459 but that the idea of the actual width of the frame should not be changed. */)
2460 (frame, cols, pretend)
2461 Lisp_Object frame, cols, pretend;
2463 register struct frame *f;
2464 CHECK_NUMBER (cols);
2465 if (NILP (frame))
2466 frame = selected_frame;
2467 CHECK_LIVE_FRAME (frame);
2468 f = XFRAME (frame);
2470 /* I think this should be done with a hook. */
2471 #ifdef HAVE_WINDOW_SYSTEM
2472 if (FRAME_WINDOW_P (f))
2474 if (XINT (cols) != FRAME_COLS (f))
2475 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2476 do_pending_window_change (0);
2478 else
2479 #endif
2480 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2481 return Qnil;
2484 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2485 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2486 (frame, cols, rows)
2487 Lisp_Object frame, cols, rows;
2489 register struct frame *f;
2491 CHECK_LIVE_FRAME (frame);
2492 CHECK_NUMBER (cols);
2493 CHECK_NUMBER (rows);
2494 f = XFRAME (frame);
2496 /* I think this should be done with a hook. */
2497 #ifdef HAVE_WINDOW_SYSTEM
2498 if (FRAME_WINDOW_P (f))
2500 if (XINT (rows) != FRAME_LINES (f)
2501 || XINT (cols) != FRAME_COLS (f)
2502 || f->new_text_lines || f->new_text_cols)
2503 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2504 do_pending_window_change (0);
2506 else
2507 #endif
2508 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2510 return Qnil;
2513 DEFUN ("set-frame-position", Fset_frame_position,
2514 Sset_frame_position, 3, 3, 0,
2515 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2516 This is actually the position of the upper left corner of the frame.
2517 Negative values for XOFFSET or YOFFSET are interpreted relative to
2518 the rightmost or bottommost possible position (that stays within the screen). */)
2519 (frame, xoffset, yoffset)
2520 Lisp_Object frame, xoffset, yoffset;
2522 register struct frame *f;
2524 CHECK_LIVE_FRAME (frame);
2525 CHECK_NUMBER (xoffset);
2526 CHECK_NUMBER (yoffset);
2527 f = XFRAME (frame);
2529 /* I think this should be done with a hook. */
2530 #ifdef HAVE_WINDOW_SYSTEM
2531 if (FRAME_WINDOW_P (f))
2532 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2533 #endif
2535 return Qt;
2539 /***********************************************************************
2540 Frame Parameters
2541 ***********************************************************************/
2543 /* Connect the frame-parameter names for X frames
2544 to the ways of passing the parameter values to the window system.
2546 The name of a parameter, as a Lisp symbol,
2547 has an `x-frame-parameter' property which is an integer in Lisp
2548 that is an index in this table. */
2550 struct frame_parm_table {
2551 char *name;
2552 Lisp_Object *variable;
2555 static struct frame_parm_table frame_parms[] =
2557 {"auto-raise", &Qauto_raise},
2558 {"auto-lower", &Qauto_lower},
2559 {"background-color", 0},
2560 {"border-color", &Qborder_color},
2561 {"border-width", &Qborder_width},
2562 {"cursor-color", &Qcursor_color},
2563 {"cursor-type", &Qcursor_type},
2564 {"font", 0},
2565 {"foreground-color", 0},
2566 {"icon-name", &Qicon_name},
2567 {"icon-type", &Qicon_type},
2568 {"internal-border-width", &Qinternal_border_width},
2569 {"menu-bar-lines", &Qmenu_bar_lines},
2570 {"mouse-color", &Qmouse_color},
2571 {"name", &Qname},
2572 {"scroll-bar-width", &Qscroll_bar_width},
2573 {"title", &Qtitle},
2574 {"unsplittable", &Qunsplittable},
2575 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2576 {"visibility", &Qvisibility},
2577 {"tool-bar-lines", &Qtool_bar_lines},
2578 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2579 {"scroll-bar-background", &Qscroll_bar_background},
2580 {"screen-gamma", &Qscreen_gamma},
2581 {"line-spacing", &Qline_spacing},
2582 {"left-fringe", &Qleft_fringe},
2583 {"right-fringe", &Qright_fringe},
2584 {"wait-for-wm", &Qwait_for_wm},
2585 {"fullscreen", &Qfullscreen},
2588 #ifdef HAVE_WINDOW_SYSTEM
2590 extern Lisp_Object Qbox;
2591 extern Lisp_Object Qtop;
2593 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2594 wanted positions of the WM window (not Emacs window).
2595 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2596 window (FRAME_X_WINDOW).
2599 void
2600 x_fullscreen_adjust (f, width, height, top_pos, left_pos)
2601 struct frame *f;
2602 int *width;
2603 int *height;
2604 int *top_pos;
2605 int *left_pos;
2607 int newwidth = FRAME_COLS (f);
2608 int newheight = FRAME_LINES (f);
2610 *top_pos = f->top_pos;
2611 *left_pos = f->left_pos;
2613 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2615 int ph;
2617 ph = FRAME_X_DISPLAY_INFO (f)->height;
2618 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2619 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2620 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2621 *top_pos = 0;
2624 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2626 int pw;
2628 pw = FRAME_X_DISPLAY_INFO (f)->width;
2629 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2630 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2631 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2632 *left_pos = 0;
2635 *width = newwidth;
2636 *height = newheight;
2640 /* Change the parameters of frame F as specified by ALIST.
2641 If a parameter is not specially recognized, do nothing special;
2642 otherwise call the `x_set_...' function for that parameter.
2643 Except for certain geometry properties, always call store_frame_param
2644 to store the new value in the parameter alist. */
2646 void
2647 x_set_frame_parameters (f, alist)
2648 FRAME_PTR f;
2649 Lisp_Object alist;
2651 Lisp_Object tail;
2653 /* If both of these parameters are present, it's more efficient to
2654 set them both at once. So we wait until we've looked at the
2655 entire list before we set them. */
2656 int width, height;
2658 /* Same here. */
2659 Lisp_Object left, top;
2661 /* Same with these. */
2662 Lisp_Object icon_left, icon_top;
2664 /* Record in these vectors all the parms specified. */
2665 Lisp_Object *parms;
2666 Lisp_Object *values;
2667 int i, p;
2668 int left_no_change = 0, top_no_change = 0;
2669 int icon_left_no_change = 0, icon_top_no_change = 0;
2670 int fullscreen_is_being_set = 0;
2672 struct gcpro gcpro1, gcpro2;
2674 i = 0;
2675 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2676 i++;
2678 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2679 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2681 /* Extract parm names and values into those vectors. */
2683 i = 0;
2684 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2686 Lisp_Object elt;
2688 elt = Fcar (tail);
2689 parms[i] = Fcar (elt);
2690 values[i] = Fcdr (elt);
2691 i++;
2693 /* TAIL and ALIST are not used again below here. */
2694 alist = tail = Qnil;
2696 GCPRO2 (*parms, *values);
2697 gcpro1.nvars = i;
2698 gcpro2.nvars = i;
2700 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2701 because their values appear in VALUES and strings are not valid. */
2702 top = left = Qunbound;
2703 icon_left = icon_top = Qunbound;
2705 /* Provide default values for HEIGHT and WIDTH. */
2706 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2707 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2709 /* Process foreground_color and background_color before anything else.
2710 They are independent of other properties, but other properties (e.g.,
2711 cursor_color) are dependent upon them. */
2712 /* Process default font as well, since fringe widths depends on it. */
2713 /* Also, process fullscreen, width and height depend upon that */
2714 for (p = 0; p < i; p++)
2716 Lisp_Object prop, val;
2718 prop = parms[p];
2719 val = values[p];
2720 if (EQ (prop, Qforeground_color)
2721 || EQ (prop, Qbackground_color)
2722 || EQ (prop, Qfont)
2723 || EQ (prop, Qfullscreen))
2725 register Lisp_Object param_index, old_value;
2726 int count = SPECPDL_INDEX ();
2728 old_value = get_frame_param (f, prop);
2729 fullscreen_is_being_set |= EQ (prop, Qfullscreen);
2731 if (NILP (Fequal (val, old_value)))
2733 /* For :font attributes, the frame_parm_handler
2734 x_set_font calls `face-set-after-frame-default'.
2735 Unless we bind inhibit-face-set-after-frame-default
2736 here, this would reset the :font attribute that we
2737 just applied to the default value for new faces. */
2738 specbind (Qinhibit_face_set_after_frame_default, Qt);
2740 store_frame_param (f, prop, val);
2742 param_index = Fget (prop, Qx_frame_parameter);
2743 if (NATNUMP (param_index)
2744 && (XFASTINT (param_index)
2745 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2746 && rif->frame_parm_handlers[XINT (param_index)])
2747 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2749 unbind_to (count, Qnil);
2754 /* Now process them in reverse of specified order. */
2755 for (i--; i >= 0; i--)
2757 Lisp_Object prop, val;
2759 prop = parms[i];
2760 val = values[i];
2762 if (EQ (prop, Qwidth) && NUMBERP (val))
2763 width = XFASTINT (val);
2764 else if (EQ (prop, Qheight) && NUMBERP (val))
2765 height = XFASTINT (val);
2766 else if (EQ (prop, Qtop))
2767 top = val;
2768 else if (EQ (prop, Qleft))
2769 left = val;
2770 else if (EQ (prop, Qicon_top))
2771 icon_top = val;
2772 else if (EQ (prop, Qicon_left))
2773 icon_left = val;
2774 else if (EQ (prop, Qforeground_color)
2775 || EQ (prop, Qbackground_color)
2776 || EQ (prop, Qfont)
2777 || EQ (prop, Qfullscreen))
2778 /* Processed above. */
2779 continue;
2780 else
2782 register Lisp_Object param_index, old_value;
2784 old_value = get_frame_param (f, prop);
2786 store_frame_param (f, prop, val);
2788 param_index = Fget (prop, Qx_frame_parameter);
2789 if (NATNUMP (param_index)
2790 && (XFASTINT (param_index)
2791 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2792 && rif->frame_parm_handlers[XINT (param_index)])
2793 (*(rif->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2797 /* Don't die if just one of these was set. */
2798 if (EQ (left, Qunbound))
2800 left_no_change = 1;
2801 if (f->left_pos < 0)
2802 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2803 else
2804 XSETINT (left, f->left_pos);
2806 if (EQ (top, Qunbound))
2808 top_no_change = 1;
2809 if (f->top_pos < 0)
2810 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2811 else
2812 XSETINT (top, f->top_pos);
2815 /* If one of the icon positions was not set, preserve or default it. */
2816 if (EQ (icon_left, Qunbound) || ! INTEGERP (icon_left))
2818 icon_left_no_change = 1;
2819 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2820 if (NILP (icon_left))
2821 XSETINT (icon_left, 0);
2823 if (EQ (icon_top, Qunbound) || ! INTEGERP (icon_top))
2825 icon_top_no_change = 1;
2826 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2827 if (NILP (icon_top))
2828 XSETINT (icon_top, 0);
2831 if (FRAME_VISIBLE_P (f) && fullscreen_is_being_set)
2833 /* If the frame is visible already and the fullscreen parameter is
2834 being set, it is too late to set WM manager hints to specify
2835 size and position.
2836 Here we first get the width, height and position that applies to
2837 fullscreen. We then move the frame to the appropriate
2838 position. Resize of the frame is taken care of in the code after
2839 this if-statement. */
2840 int new_left, new_top;
2842 x_fullscreen_adjust (f, &width, &height, &new_top, &new_left);
2843 if (new_top != f->top_pos || new_left != f->left_pos)
2844 x_set_offset (f, new_left, new_top, 1);
2847 /* Don't set these parameters unless they've been explicitly
2848 specified. The window might be mapped or resized while we're in
2849 this function, and we don't want to override that unless the lisp
2850 code has asked for it.
2852 Don't set these parameters unless they actually differ from the
2853 window's current parameters; the window may not actually exist
2854 yet. */
2856 Lisp_Object frame;
2858 check_frame_size (f, &height, &width);
2860 XSETFRAME (frame, f);
2862 if (width != FRAME_COLS (f)
2863 || height != FRAME_LINES (f)
2864 || f->new_text_lines || f->new_text_cols)
2865 Fset_frame_size (frame, make_number (width), make_number (height));
2867 if ((!NILP (left) || !NILP (top))
2868 && ! (left_no_change && top_no_change)
2869 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2870 && NUMBERP (top) && XINT (top) == f->top_pos))
2872 int leftpos = 0;
2873 int toppos = 0;
2875 /* Record the signs. */
2876 f->size_hint_flags &= ~ (XNegative | YNegative);
2877 if (EQ (left, Qminus))
2878 f->size_hint_flags |= XNegative;
2879 else if (INTEGERP (left))
2881 leftpos = XINT (left);
2882 if (leftpos < 0)
2883 f->size_hint_flags |= XNegative;
2885 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2886 && CONSP (XCDR (left))
2887 && INTEGERP (XCAR (XCDR (left))))
2889 leftpos = - XINT (XCAR (XCDR (left)));
2890 f->size_hint_flags |= XNegative;
2892 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2893 && CONSP (XCDR (left))
2894 && INTEGERP (XCAR (XCDR (left))))
2896 leftpos = XINT (XCAR (XCDR (left)));
2899 if (EQ (top, Qminus))
2900 f->size_hint_flags |= YNegative;
2901 else if (INTEGERP (top))
2903 toppos = XINT (top);
2904 if (toppos < 0)
2905 f->size_hint_flags |= YNegative;
2907 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2908 && CONSP (XCDR (top))
2909 && INTEGERP (XCAR (XCDR (top))))
2911 toppos = - XINT (XCAR (XCDR (top)));
2912 f->size_hint_flags |= YNegative;
2914 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2915 && CONSP (XCDR (top))
2916 && INTEGERP (XCAR (XCDR (top))))
2918 toppos = XINT (XCAR (XCDR (top)));
2922 /* Store the numeric value of the position. */
2923 f->top_pos = toppos;
2924 f->left_pos = leftpos;
2926 f->win_gravity = NorthWestGravity;
2928 /* Actually set that position, and convert to absolute. */
2929 x_set_offset (f, leftpos, toppos, -1);
2932 if ((!NILP (icon_left) || !NILP (icon_top))
2933 && ! (icon_left_no_change && icon_top_no_change))
2934 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2937 UNGCPRO;
2941 /* Insert a description of internally-recorded parameters of frame X
2942 into the parameter alist *ALISTPTR that is to be given to the user.
2943 Only parameters that are specific to the X window system
2944 and whose values are not correctly recorded in the frame's
2945 param_alist need to be considered here. */
2947 void
2948 x_report_frame_params (f, alistptr)
2949 struct frame *f;
2950 Lisp_Object *alistptr;
2952 char buf[16];
2953 Lisp_Object tem;
2955 /* Represent negative positions (off the top or left screen edge)
2956 in a way that Fmodify_frame_parameters will understand correctly. */
2957 XSETINT (tem, f->left_pos);
2958 if (f->left_pos >= 0)
2959 store_in_alist (alistptr, Qleft, tem);
2960 else
2961 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
2963 XSETINT (tem, f->top_pos);
2964 if (f->top_pos >= 0)
2965 store_in_alist (alistptr, Qtop, tem);
2966 else
2967 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
2969 store_in_alist (alistptr, Qborder_width,
2970 make_number (f->border_width));
2971 store_in_alist (alistptr, Qinternal_border_width,
2972 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
2973 store_in_alist (alistptr, Qleft_fringe,
2974 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
2975 store_in_alist (alistptr, Qright_fringe,
2976 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
2977 store_in_alist (alistptr, Qscroll_bar_width,
2978 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
2979 ? make_number (0)
2980 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
2981 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
2982 /* nil means "use default width"
2983 for non-toolkit scroll bar.
2984 ruler-mode.el depends on this. */
2985 : Qnil));
2986 sprintf (buf, "%ld", (long) FRAME_X_WINDOW (f));
2987 store_in_alist (alistptr, Qwindow_id,
2988 build_string (buf));
2989 #ifdef HAVE_X_WINDOWS
2990 #ifdef USE_X_TOOLKIT
2991 /* Tooltip frame may not have this widget. */
2992 if (FRAME_X_OUTPUT (f)->widget)
2993 #endif
2994 sprintf (buf, "%ld", (long) FRAME_OUTER_WINDOW (f));
2995 store_in_alist (alistptr, Qouter_window_id,
2996 build_string (buf));
2997 #endif
2998 store_in_alist (alistptr, Qicon_name, f->icon_name);
2999 FRAME_SAMPLE_VISIBILITY (f);
3000 store_in_alist (alistptr, Qvisibility,
3001 (FRAME_VISIBLE_P (f) ? Qt
3002 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3003 store_in_alist (alistptr, Qdisplay,
3004 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3006 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3007 tem = Qnil;
3008 else
3009 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3010 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3011 store_in_alist (alistptr, Qparent_id, tem);
3015 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3016 the previous value of that parameter, NEW_VALUE is the new value. */
3018 void
3019 x_set_fullscreen (f, new_value, old_value)
3020 struct frame *f;
3021 Lisp_Object new_value, old_value;
3023 if (NILP (new_value))
3024 f->want_fullscreen = FULLSCREEN_NONE;
3025 else if (EQ (new_value, Qfullboth))
3026 f->want_fullscreen = FULLSCREEN_BOTH;
3027 else if (EQ (new_value, Qfullwidth))
3028 f->want_fullscreen = FULLSCREEN_WIDTH;
3029 else if (EQ (new_value, Qfullheight))
3030 f->want_fullscreen = FULLSCREEN_HEIGHT;
3032 if (fullscreen_hook != NULL)
3033 fullscreen_hook (f);
3037 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3038 the previous value of that parameter, NEW_VALUE is the new value. */
3040 void
3041 x_set_line_spacing (f, new_value, old_value)
3042 struct frame *f;
3043 Lisp_Object new_value, old_value;
3045 if (NILP (new_value))
3046 f->extra_line_spacing = 0;
3047 else if (NATNUMP (new_value))
3048 f->extra_line_spacing = XFASTINT (new_value);
3049 else
3050 signal_error ("Invalid line-spacing", new_value);
3051 if (FRAME_VISIBLE_P (f))
3052 redraw_frame (f);
3056 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3057 the previous value of that parameter, NEW_VALUE is the new value. */
3059 void
3060 x_set_screen_gamma (f, new_value, old_value)
3061 struct frame *f;
3062 Lisp_Object new_value, old_value;
3064 Lisp_Object bgcolor;
3066 if (NILP (new_value))
3067 f->gamma = 0;
3068 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3069 /* The value 0.4545 is the normal viewing gamma. */
3070 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3071 else
3072 signal_error ("Invalid screen-gamma", new_value);
3074 /* Apply the new gamma value to the frame background. */
3075 bgcolor = Fassq (Qbackground_color, f->param_alist);
3076 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3078 Lisp_Object index = Fget (Qbackground_color, Qx_frame_parameter);
3079 if (NATNUMP (index)
3080 && (XFASTINT (index)
3081 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3082 && rif->frame_parm_handlers[XFASTINT (index)])
3083 (*(rif->frame_parm_handlers[XFASTINT (index)]))
3084 (f, bgcolor, Qnil);
3087 Fclear_face_cache (Qnil);
3091 void
3092 x_set_font (f, arg, oldval)
3093 struct frame *f;
3094 Lisp_Object arg, oldval;
3096 Lisp_Object result;
3097 Lisp_Object fontset_name;
3098 Lisp_Object frame;
3099 int old_fontset = FRAME_FONTSET(f);
3101 CHECK_STRING (arg);
3103 fontset_name = Fquery_fontset (arg, Qnil);
3105 BLOCK_INPUT;
3106 result = (STRINGP (fontset_name)
3107 ? x_new_fontset (f, SDATA (fontset_name))
3108 : x_new_font (f, SDATA (arg)));
3109 UNBLOCK_INPUT;
3111 if (EQ (result, Qnil))
3112 error ("Font `%s' is not defined", SDATA (arg));
3113 else if (EQ (result, Qt))
3114 error ("The characters of the given font have varying widths");
3115 else if (STRINGP (result))
3117 set_default_ascii_font (result);
3118 if (STRINGP (fontset_name))
3120 /* Fontset names are built from ASCII font names, so the
3121 names may be equal despite there was a change. */
3122 if (old_fontset == FRAME_FONTSET (f))
3123 return;
3125 else if (!NILP (Fequal (result, oldval)))
3126 return;
3128 /* Recalculate toolbar height. */
3129 f->n_tool_bar_rows = 0;
3130 /* Ensure we redraw it. */
3131 clear_current_matrices (f);
3133 store_frame_param (f, Qfont, result);
3134 recompute_basic_faces (f);
3136 else
3137 abort ();
3139 do_pending_window_change (0);
3141 /* Don't call `face-set-after-frame-default' when faces haven't been
3142 initialized yet. This is the case when called from
3143 Fx_create_frame. In that case, the X widget or window doesn't
3144 exist either, and we can end up in x_report_frame_params with a
3145 null widget which gives a segfault. */
3146 if (FRAME_FACE_CACHE (f))
3148 XSETFRAME (frame, f);
3149 call1 (Qface_set_after_frame_default, frame);
3154 void
3155 x_set_fringe_width (f, new_value, old_value)
3156 struct frame *f;
3157 Lisp_Object new_value, old_value;
3159 compute_fringe_widths (f, 1);
3162 void
3163 x_set_border_width (f, arg, oldval)
3164 struct frame *f;
3165 Lisp_Object arg, oldval;
3167 CHECK_NUMBER (arg);
3169 if (XINT (arg) == f->border_width)
3170 return;
3172 if (FRAME_X_WINDOW (f) != 0)
3173 error ("Cannot change the border width of a frame");
3175 f->border_width = XINT (arg);
3178 void
3179 x_set_internal_border_width (f, arg, oldval)
3180 struct frame *f;
3181 Lisp_Object arg, oldval;
3183 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3185 CHECK_NUMBER (arg);
3186 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3187 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3188 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3190 #ifdef USE_X_TOOLKIT
3191 if (FRAME_X_OUTPUT (f)->edit_widget)
3192 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3193 #endif
3195 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3196 return;
3198 if (FRAME_X_WINDOW (f) != 0)
3200 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3201 SET_FRAME_GARBAGED (f);
3202 do_pending_window_change (0);
3204 else
3205 SET_FRAME_GARBAGED (f);
3208 void
3209 x_set_visibility (f, value, oldval)
3210 struct frame *f;
3211 Lisp_Object value, oldval;
3213 Lisp_Object frame;
3214 XSETFRAME (frame, f);
3216 if (NILP (value))
3217 Fmake_frame_invisible (frame, Qt);
3218 else if (EQ (value, Qicon))
3219 Ficonify_frame (frame);
3220 else
3221 Fmake_frame_visible (frame);
3224 void
3225 x_set_autoraise (f, arg, oldval)
3226 struct frame *f;
3227 Lisp_Object arg, oldval;
3229 f->auto_raise = !EQ (Qnil, arg);
3232 void
3233 x_set_autolower (f, arg, oldval)
3234 struct frame *f;
3235 Lisp_Object arg, oldval;
3237 f->auto_lower = !EQ (Qnil, arg);
3240 void
3241 x_set_unsplittable (f, arg, oldval)
3242 struct frame *f;
3243 Lisp_Object arg, oldval;
3245 f->no_split = !NILP (arg);
3248 void
3249 x_set_vertical_scroll_bars (f, arg, oldval)
3250 struct frame *f;
3251 Lisp_Object arg, oldval;
3253 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3254 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3255 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3256 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3258 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3259 = (NILP (arg)
3260 ? vertical_scroll_bar_none
3261 : EQ (Qleft, arg)
3262 ? vertical_scroll_bar_left
3263 : EQ (Qright, arg)
3264 ? vertical_scroll_bar_right
3265 : EQ (Qleft, Vdefault_frame_scroll_bars)
3266 ? vertical_scroll_bar_left
3267 : EQ (Qright, Vdefault_frame_scroll_bars)
3268 ? vertical_scroll_bar_right
3269 : vertical_scroll_bar_none);
3271 /* We set this parameter before creating the X window for the
3272 frame, so we can get the geometry right from the start.
3273 However, if the window hasn't been created yet, we shouldn't
3274 call x_set_window_size. */
3275 if (FRAME_X_WINDOW (f))
3276 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3277 do_pending_window_change (0);
3281 void
3282 x_set_scroll_bar_width (f, arg, oldval)
3283 struct frame *f;
3284 Lisp_Object arg, oldval;
3286 int wid = FRAME_COLUMN_WIDTH (f);
3288 if (NILP (arg))
3290 x_set_scroll_bar_default_width (f);
3292 if (FRAME_X_WINDOW (f))
3293 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3294 do_pending_window_change (0);
3296 else if (INTEGERP (arg) && XINT (arg) > 0
3297 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3299 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3300 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3302 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3303 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3304 if (FRAME_X_WINDOW (f))
3305 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3306 do_pending_window_change (0);
3309 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3310 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3311 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3316 /* Return non-nil if frame F wants a bitmap icon. */
3318 Lisp_Object
3319 x_icon_type (f)
3320 FRAME_PTR f;
3322 Lisp_Object tem;
3324 tem = assq_no_quit (Qicon_type, f->param_alist);
3325 if (CONSP (tem))
3326 return XCDR (tem);
3327 else
3328 return Qnil;
3332 /* Subroutines of creating an X frame. */
3334 /* Make sure that Vx_resource_name is set to a reasonable value.
3335 Fix it up, or set it to `emacs' if it is too hopeless. */
3337 void
3338 validate_x_resource_name ()
3340 int len = 0;
3341 /* Number of valid characters in the resource name. */
3342 int good_count = 0;
3343 /* Number of invalid characters in the resource name. */
3344 int bad_count = 0;
3345 Lisp_Object new;
3346 int i;
3348 if (!STRINGP (Vx_resource_class))
3349 Vx_resource_class = build_string (EMACS_CLASS);
3351 if (STRINGP (Vx_resource_name))
3353 unsigned char *p = SDATA (Vx_resource_name);
3354 int i;
3356 len = SBYTES (Vx_resource_name);
3358 /* Only letters, digits, - and _ are valid in resource names.
3359 Count the valid characters and count the invalid ones. */
3360 for (i = 0; i < len; i++)
3362 int c = p[i];
3363 if (! ((c >= 'a' && c <= 'z')
3364 || (c >= 'A' && c <= 'Z')
3365 || (c >= '0' && c <= '9')
3366 || c == '-' || c == '_'))
3367 bad_count++;
3368 else
3369 good_count++;
3372 else
3373 /* Not a string => completely invalid. */
3374 bad_count = 5, good_count = 0;
3376 /* If name is valid already, return. */
3377 if (bad_count == 0)
3378 return;
3380 /* If name is entirely invalid, or nearly so, use `emacs'. */
3381 if (good_count == 0
3382 || (good_count == 1 && bad_count > 0))
3384 Vx_resource_name = build_string ("emacs");
3385 return;
3388 /* Name is partly valid. Copy it and replace the invalid characters
3389 with underscores. */
3391 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3393 for (i = 0; i < len; i++)
3395 int c = SREF (new, i);
3396 if (! ((c >= 'a' && c <= 'z')
3397 || (c >= 'A' && c <= 'Z')
3398 || (c >= '0' && c <= '9')
3399 || c == '-' || c == '_'))
3400 SSET (new, i, '_');
3405 extern char *x_get_string_resource P_ ((XrmDatabase, char *, char *));
3406 extern Display_Info *check_x_display_info P_ ((Lisp_Object));
3409 /* Get specified attribute from resource database RDB.
3410 See Fx_get_resource below for other parameters. */
3412 static Lisp_Object
3413 xrdb_get_resource (rdb, attribute, class, component, subclass)
3414 XrmDatabase rdb;
3415 Lisp_Object attribute, class, component, subclass;
3417 register char *value;
3418 char *name_key;
3419 char *class_key;
3421 CHECK_STRING (attribute);
3422 CHECK_STRING (class);
3424 if (!NILP (component))
3425 CHECK_STRING (component);
3426 if (!NILP (subclass))
3427 CHECK_STRING (subclass);
3428 if (NILP (component) != NILP (subclass))
3429 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3431 validate_x_resource_name ();
3433 /* Allocate space for the components, the dots which separate them,
3434 and the final '\0'. Make them big enough for the worst case. */
3435 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3436 + (STRINGP (component)
3437 ? SBYTES (component) : 0)
3438 + SBYTES (attribute)
3439 + 3);
3441 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3442 + SBYTES (class)
3443 + (STRINGP (subclass)
3444 ? SBYTES (subclass) : 0)
3445 + 3);
3447 /* Start with emacs.FRAMENAME for the name (the specific one)
3448 and with `Emacs' for the class key (the general one). */
3449 strcpy (name_key, SDATA (Vx_resource_name));
3450 strcpy (class_key, SDATA (Vx_resource_class));
3452 strcat (class_key, ".");
3453 strcat (class_key, SDATA (class));
3455 if (!NILP (component))
3457 strcat (class_key, ".");
3458 strcat (class_key, SDATA (subclass));
3460 strcat (name_key, ".");
3461 strcat (name_key, SDATA (component));
3464 strcat (name_key, ".");
3465 strcat (name_key, SDATA (attribute));
3467 value = x_get_string_resource (rdb, name_key, class_key);
3469 if (value != (char *) 0)
3470 return build_string (value);
3471 else
3472 return Qnil;
3476 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3477 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3478 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3479 class, where INSTANCE is the name under which Emacs was invoked, or
3480 the name specified by the `-name' or `-rn' command-line arguments.
3482 The optional arguments COMPONENT and SUBCLASS add to the key and the
3483 class, respectively. You must specify both of them or neither.
3484 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3485 and the class is `Emacs.CLASS.SUBCLASS'. */)
3486 (attribute, class, component, subclass)
3487 Lisp_Object attribute, class, component, subclass;
3489 #ifdef HAVE_X_WINDOWS
3490 check_x ();
3491 #endif
3493 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3494 attribute, class, component, subclass);
3497 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3499 Lisp_Object
3500 display_x_get_resource (dpyinfo, attribute, class, component, subclass)
3501 Display_Info *dpyinfo;
3502 Lisp_Object attribute, class, component, subclass;
3504 return xrdb_get_resource (dpyinfo->xrdb,
3505 attribute, class, component, subclass);
3508 /* Used when C code wants a resource value. */
3510 char *
3511 x_get_resource_string (attribute, class)
3512 char *attribute, *class;
3514 char *name_key;
3515 char *class_key;
3516 struct frame *sf = SELECTED_FRAME ();
3518 /* Allocate space for the components, the dots which separate them,
3519 and the final '\0'. */
3520 name_key = (char *) alloca (SBYTES (Vinvocation_name)
3521 + strlen (attribute) + 2);
3522 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3523 + strlen (class) + 2);
3525 sprintf (name_key, "%s.%s", SDATA (Vinvocation_name), attribute);
3526 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3528 return x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3529 name_key, class_key);
3533 /* Return the value of parameter PARAM.
3535 First search ALIST, then Vdefault_frame_alist, then the X defaults
3536 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3538 Convert the resource to the type specified by desired_type.
3540 If no default is specified, return Qunbound. If you call
3541 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3542 and don't let it get stored in any Lisp-visible variables! */
3544 Lisp_Object
3545 x_get_arg (dpyinfo, alist, param, attribute, class, type)
3546 Display_Info *dpyinfo;
3547 Lisp_Object alist, param;
3548 char *attribute;
3549 char *class;
3550 enum resource_types type;
3552 register Lisp_Object tem;
3554 tem = Fassq (param, alist);
3556 if (!NILP (tem))
3558 /* If we find this parm in ALIST, clear it out
3559 so that it won't be "left over" at the end. */
3560 #ifndef WINDOWSNT /* w32fns.c has not yet been changed to cope with this. */
3561 Lisp_Object tail;
3562 XSETCAR (tem, Qnil);
3563 /* In case the parameter appears more than once in the alist,
3564 clear it out. */
3565 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3566 if (CONSP (XCAR (tail))
3567 && EQ (XCAR (XCAR (tail)), param))
3568 XSETCAR (XCAR (tail), Qnil);
3569 #endif
3571 else
3572 tem = Fassq (param, Vdefault_frame_alist);
3574 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3575 look in the X resources. */
3576 if (EQ (tem, Qnil))
3578 if (attribute)
3580 tem = display_x_get_resource (dpyinfo,
3581 build_string (attribute),
3582 build_string (class),
3583 Qnil, Qnil);
3585 if (NILP (tem))
3586 return Qunbound;
3588 switch (type)
3590 case RES_TYPE_NUMBER:
3591 return make_number (atoi (SDATA (tem)));
3593 case RES_TYPE_FLOAT:
3594 return make_float (atof (SDATA (tem)));
3596 case RES_TYPE_BOOLEAN:
3597 tem = Fdowncase (tem);
3598 if (!strcmp (SDATA (tem), "on")
3599 || !strcmp (SDATA (tem), "true"))
3600 return Qt;
3601 else
3602 return Qnil;
3604 case RES_TYPE_STRING:
3605 return tem;
3607 case RES_TYPE_SYMBOL:
3608 /* As a special case, we map the values `true' and `on'
3609 to Qt, and `false' and `off' to Qnil. */
3611 Lisp_Object lower;
3612 lower = Fdowncase (tem);
3613 if (!strcmp (SDATA (lower), "on")
3614 || !strcmp (SDATA (lower), "true"))
3615 return Qt;
3616 else if (!strcmp (SDATA (lower), "off")
3617 || !strcmp (SDATA (lower), "false"))
3618 return Qnil;
3619 else
3620 return Fintern (tem, Qnil);
3623 default:
3624 abort ();
3627 else
3628 return Qunbound;
3630 return Fcdr (tem);
3633 Lisp_Object
3634 x_frame_get_arg (f, alist, param, attribute, class, type)
3635 struct frame *f;
3636 Lisp_Object alist, param;
3637 char *attribute;
3638 char *class;
3639 enum resource_types type;
3641 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3642 alist, param, attribute, class, type);
3645 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3647 Lisp_Object
3648 x_frame_get_and_record_arg (f, alist, param, attribute, class, type)
3649 struct frame *f;
3650 Lisp_Object alist, param;
3651 char *attribute;
3652 char *class;
3653 enum resource_types type;
3655 Lisp_Object value;
3657 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3658 attribute, class, type);
3659 if (! NILP (value) && ! EQ (value, Qunbound))
3660 store_frame_param (f, param, value);
3662 return value;
3666 /* Record in frame F the specified or default value according to ALIST
3667 of the parameter named PROP (a Lisp symbol).
3668 If no value is specified for PROP, look for an X default for XPROP
3669 on the frame named NAME.
3670 If that is not found either, use the value DEFLT. */
3672 Lisp_Object
3673 x_default_parameter (f, alist, prop, deflt, xprop, xclass, type)
3674 struct frame *f;
3675 Lisp_Object alist;
3676 Lisp_Object prop;
3677 Lisp_Object deflt;
3678 char *xprop;
3679 char *xclass;
3680 enum resource_types type;
3682 Lisp_Object tem;
3684 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3685 if (EQ (tem, Qunbound))
3686 tem = deflt;
3687 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3688 return tem;
3694 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3695 doc: /* Parse an X-style geometry string STRING.
3696 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3697 The properties returned may include `top', `left', `height', and `width'.
3698 The value of `left' or `top' may be an integer,
3699 or a list (+ N) meaning N pixels relative to top/left corner,
3700 or a list (- N) meaning -N pixels relative to bottom/right corner. */)
3701 (string)
3702 Lisp_Object string;
3704 int geometry, x, y;
3705 unsigned int width, height;
3706 Lisp_Object result;
3708 CHECK_STRING (string);
3710 geometry = XParseGeometry ((char *) SDATA (string),
3711 &x, &y, &width, &height);
3713 #if 0
3714 if (!!(geometry & XValue) != !!(geometry & YValue))
3715 error ("Must specify both x and y position, or neither");
3716 #endif
3718 result = Qnil;
3719 if (geometry & XValue)
3721 Lisp_Object element;
3723 if (x >= 0 && (geometry & XNegative))
3724 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3725 else if (x < 0 && ! (geometry & XNegative))
3726 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3727 else
3728 element = Fcons (Qleft, make_number (x));
3729 result = Fcons (element, result);
3732 if (geometry & YValue)
3734 Lisp_Object element;
3736 if (y >= 0 && (geometry & YNegative))
3737 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3738 else if (y < 0 && ! (geometry & YNegative))
3739 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3740 else
3741 element = Fcons (Qtop, make_number (y));
3742 result = Fcons (element, result);
3745 if (geometry & WidthValue)
3746 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3747 if (geometry & HeightValue)
3748 result = Fcons (Fcons (Qheight, make_number (height)), result);
3750 return result;
3753 /* Calculate the desired size and position of frame F.
3754 Return the flags saying which aspects were specified.
3756 Also set the win_gravity and size_hint_flags of F.
3758 Adjust height for toolbar if TOOLBAR_P is 1.
3760 This function does not make the coordinates positive. */
3762 #define DEFAULT_ROWS 40
3763 #define DEFAULT_COLS 80
3766 x_figure_window_size (f, parms, toolbar_p)
3767 struct frame *f;
3768 Lisp_Object parms;
3769 int toolbar_p;
3771 register Lisp_Object tem0, tem1, tem2;
3772 long window_prompting = 0;
3773 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3775 /* Default values if we fall through.
3776 Actually, if that happens we should get
3777 window manager prompting. */
3778 SET_FRAME_COLS (f, DEFAULT_COLS);
3779 FRAME_LINES (f) = DEFAULT_ROWS;
3780 /* Window managers expect that if program-specified
3781 positions are not (0,0), they're intentional, not defaults. */
3782 f->top_pos = 0;
3783 f->left_pos = 0;
3785 /* Ensure that old new_text_cols and new_text_lines will not override the
3786 values set here. */
3787 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3788 f->new_text_cols = f->new_text_lines = 0;
3790 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3791 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3792 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3793 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3795 if (!EQ (tem0, Qunbound))
3797 CHECK_NUMBER (tem0);
3798 FRAME_LINES (f) = XINT (tem0);
3800 if (!EQ (tem1, Qunbound))
3802 CHECK_NUMBER (tem1);
3803 SET_FRAME_COLS (f, XINT (tem1));
3805 if (!NILP (tem2) && !EQ (tem2, Qunbound))
3806 window_prompting |= USSize;
3807 else
3808 window_prompting |= PSize;
3811 f->scroll_bar_actual_width
3812 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
3814 /* This used to be done _before_ calling x_figure_window_size, but
3815 since the height is reset here, this was really a no-op. I
3816 assume that moving it here does what Gerd intended (although he
3817 no longer can remember what that was... ++KFS, 2003-03-25. */
3819 /* Add the tool-bar height to the initial frame height so that the
3820 user gets a text display area of the size he specified with -g or
3821 via .Xdefaults. Later changes of the tool-bar height don't
3822 change the frame size. This is done so that users can create
3823 tall Emacs frames without having to guess how tall the tool-bar
3824 will get. */
3825 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
3827 int margin, relief, bar_height;
3829 relief = (tool_bar_button_relief >= 0
3830 ? tool_bar_button_relief
3831 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
3833 if (INTEGERP (Vtool_bar_button_margin)
3834 && XINT (Vtool_bar_button_margin) > 0)
3835 margin = XFASTINT (Vtool_bar_button_margin);
3836 else if (CONSP (Vtool_bar_button_margin)
3837 && INTEGERP (XCDR (Vtool_bar_button_margin))
3838 && XINT (XCDR (Vtool_bar_button_margin)) > 0)
3839 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
3840 else
3841 margin = 0;
3843 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
3844 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
3847 compute_fringe_widths (f, 0);
3849 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
3850 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
3852 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
3853 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
3854 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
3855 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3857 if (EQ (tem0, Qminus))
3859 f->top_pos = 0;
3860 window_prompting |= YNegative;
3862 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
3863 && CONSP (XCDR (tem0))
3864 && INTEGERP (XCAR (XCDR (tem0))))
3866 f->top_pos = - XINT (XCAR (XCDR (tem0)));
3867 window_prompting |= YNegative;
3869 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
3870 && CONSP (XCDR (tem0))
3871 && INTEGERP (XCAR (XCDR (tem0))))
3873 f->top_pos = XINT (XCAR (XCDR (tem0)));
3875 else if (EQ (tem0, Qunbound))
3876 f->top_pos = 0;
3877 else
3879 CHECK_NUMBER (tem0);
3880 f->top_pos = XINT (tem0);
3881 if (f->top_pos < 0)
3882 window_prompting |= YNegative;
3885 if (EQ (tem1, Qminus))
3887 f->left_pos = 0;
3888 window_prompting |= XNegative;
3890 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
3891 && CONSP (XCDR (tem1))
3892 && INTEGERP (XCAR (XCDR (tem1))))
3894 f->left_pos = - XINT (XCAR (XCDR (tem1)));
3895 window_prompting |= XNegative;
3897 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
3898 && CONSP (XCDR (tem1))
3899 && INTEGERP (XCAR (XCDR (tem1))))
3901 f->left_pos = XINT (XCAR (XCDR (tem1)));
3903 else if (EQ (tem1, Qunbound))
3904 f->left_pos = 0;
3905 else
3907 CHECK_NUMBER (tem1);
3908 f->left_pos = XINT (tem1);
3909 if (f->left_pos < 0)
3910 window_prompting |= XNegative;
3913 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
3914 window_prompting |= USPosition;
3915 else
3916 window_prompting |= PPosition;
3919 if (f->want_fullscreen != FULLSCREEN_NONE)
3921 int left, top;
3922 int width, height;
3924 /* It takes both for some WM:s to place it where we want */
3925 window_prompting = USPosition | PPosition;
3926 x_fullscreen_adjust (f, &width, &height, &top, &left);
3927 FRAME_COLS (f) = width;
3928 FRAME_LINES (f) = height;
3929 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, width);
3930 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, height);
3931 f->left_pos = left;
3932 f->top_pos = top;
3935 if (window_prompting & XNegative)
3937 if (window_prompting & YNegative)
3938 f->win_gravity = SouthEastGravity;
3939 else
3940 f->win_gravity = NorthEastGravity;
3942 else
3944 if (window_prompting & YNegative)
3945 f->win_gravity = SouthWestGravity;
3946 else
3947 f->win_gravity = NorthWestGravity;
3950 f->size_hint_flags = window_prompting;
3952 return window_prompting;
3957 #endif /* HAVE_WINDOW_SYSTEM */
3961 /***********************************************************************
3962 Initialization
3963 ***********************************************************************/
3965 void
3966 syms_of_frame ()
3968 Qframep = intern ("framep");
3969 staticpro (&Qframep);
3970 Qframe_live_p = intern ("frame-live-p");
3971 staticpro (&Qframe_live_p);
3972 Qexplicit_name = intern ("explicit-name");
3973 staticpro (&Qexplicit_name);
3974 Qheight = intern ("height");
3975 staticpro (&Qheight);
3976 Qicon = intern ("icon");
3977 staticpro (&Qicon);
3978 Qminibuffer = intern ("minibuffer");
3979 staticpro (&Qminibuffer);
3980 Qmodeline = intern ("modeline");
3981 staticpro (&Qmodeline);
3982 Qonly = intern ("only");
3983 staticpro (&Qonly);
3984 Qwidth = intern ("width");
3985 staticpro (&Qwidth);
3986 Qgeometry = intern ("geometry");
3987 staticpro (&Qgeometry);
3988 Qicon_left = intern ("icon-left");
3989 staticpro (&Qicon_left);
3990 Qicon_top = intern ("icon-top");
3991 staticpro (&Qicon_top);
3992 Qleft = intern ("left");
3993 staticpro (&Qleft);
3994 Qright = intern ("right");
3995 staticpro (&Qright);
3996 Quser_position = intern ("user-position");
3997 staticpro (&Quser_position);
3998 Quser_size = intern ("user-size");
3999 staticpro (&Quser_size);
4000 Qwindow_id = intern ("window-id");
4001 staticpro (&Qwindow_id);
4002 #ifdef HAVE_X_WINDOWS
4003 Qouter_window_id = intern ("outer-window-id");
4004 staticpro (&Qouter_window_id);
4005 #endif
4006 Qparent_id = intern ("parent-id");
4007 staticpro (&Qparent_id);
4008 Qx = intern ("x");
4009 staticpro (&Qx);
4010 Qw32 = intern ("w32");
4011 staticpro (&Qw32);
4012 Qpc = intern ("pc");
4013 staticpro (&Qpc);
4014 Qmac = intern ("mac");
4015 staticpro (&Qmac);
4016 Qvisible = intern ("visible");
4017 staticpro (&Qvisible);
4018 Qbuffer_predicate = intern ("buffer-predicate");
4019 staticpro (&Qbuffer_predicate);
4020 Qbuffer_list = intern ("buffer-list");
4021 staticpro (&Qbuffer_list);
4022 Qdisplay_type = intern ("display-type");
4023 staticpro (&Qdisplay_type);
4024 Qbackground_mode = intern ("background-mode");
4025 staticpro (&Qbackground_mode);
4026 Qtty_color_mode = intern ("tty-color-mode");
4027 staticpro (&Qtty_color_mode);
4029 Qface_set_after_frame_default = intern ("face-set-after-frame-default");
4030 staticpro (&Qface_set_after_frame_default);
4032 Qinhibit_face_set_after_frame_default
4033 = intern ("inhibit-face-set-after-frame-default");
4034 staticpro (&Qinhibit_face_set_after_frame_default);
4036 Qfullwidth = intern ("fullwidth");
4037 staticpro (&Qfullwidth);
4038 Qfullheight = intern ("fullheight");
4039 staticpro (&Qfullheight);
4040 Qfullboth = intern ("fullboth");
4041 staticpro (&Qfullboth);
4042 Qx_resource_name = intern ("x-resource-name");
4043 staticpro (&Qx_resource_name);
4045 Qx_frame_parameter = intern ("x-frame-parameter");
4046 staticpro (&Qx_frame_parameter);
4049 int i;
4051 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4053 Lisp_Object v = intern (frame_parms[i].name);
4054 if (frame_parms[i].variable)
4056 *frame_parms[i].variable = v;
4057 staticpro (frame_parms[i].variable);
4059 Fput (v, Qx_frame_parameter, make_number (i));
4063 #ifdef HAVE_WINDOW_SYSTEM
4064 DEFVAR_LISP ("x-resource-name", &Vx_resource_name,
4065 doc: /* The name Emacs uses to look up X resources.
4066 `x-get-resource' uses this as the first component of the instance name
4067 when requesting resource values.
4068 Emacs initially sets `x-resource-name' to the name under which Emacs
4069 was invoked, or to the value specified with the `-name' or `-rn'
4070 switches, if present.
4072 It may be useful to bind this variable locally around a call
4073 to `x-get-resource'. See also the variable `x-resource-class'. */);
4074 Vx_resource_name = Qnil;
4076 DEFVAR_LISP ("x-resource-class", &Vx_resource_class,
4077 doc: /* The class Emacs uses to look up X resources.
4078 `x-get-resource' uses this as the first component of the instance class
4079 when requesting resource values.
4081 Emacs initially sets `x-resource-class' to "Emacs".
4083 Setting this variable permanently is not a reasonable thing to do,
4084 but binding this variable locally around a call to `x-get-resource'
4085 is a reasonable practice. See also the variable `x-resource-name'. */);
4086 Vx_resource_class = build_string (EMACS_CLASS);
4087 #endif
4089 DEFVAR_LISP ("default-frame-alist", &Vdefault_frame_alist,
4090 doc: /* Alist of default values for frame creation.
4091 These may be set in your init file, like this:
4092 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4093 These override values given in window system configuration data,
4094 including X Windows' defaults database.
4095 For values specific to the first Emacs frame, see `initial-frame-alist'.
4096 For values specific to the separate minibuffer frame, see
4097 `minibuffer-frame-alist'.
4098 The `menu-bar-lines' element of the list controls whether new frames
4099 have menu bars; `menu-bar-mode' works by altering this element.
4100 Setting this variable does not affect existing frames, only new ones. */);
4101 Vdefault_frame_alist = Qnil;
4103 DEFVAR_LISP ("default-frame-scroll-bars", &Vdefault_frame_scroll_bars,
4104 doc: /* Default position of scroll bars on this window-system. */);
4105 #ifdef HAVE_WINDOW_SYSTEM
4106 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4107 /* MS-Windows has scroll bars on the right by default. */
4108 Vdefault_frame_scroll_bars = Qright;
4109 #else
4110 Vdefault_frame_scroll_bars = Qleft;
4111 #endif
4112 #else
4113 Vdefault_frame_scroll_bars = Qnil;
4114 #endif
4116 DEFVAR_LISP ("terminal-frame", &Vterminal_frame,
4117 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4119 DEFVAR_LISP ("emacs-iconified", &Vemacs_iconified,
4120 doc: /* Non-nil if all of Emacs is iconified and frame updates are not needed. */);
4121 Vemacs_iconified = Qnil;
4123 DEFVAR_LISP ("mouse-position-function", &Vmouse_position_function,
4124 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4125 `mouse-position' calls this function, passing its usual return value as
4126 argument, and returns whatever this function returns.
4127 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4128 which need to do mouse handling at the Lisp level. */);
4129 Vmouse_position_function = Qnil;
4131 DEFVAR_LISP ("mouse-highlight", &Vmouse_highlight,
4132 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4133 If the value is an integer, highlighting is only shown after moving the
4134 mouse, while keyboard input turns off the highlight even when the mouse
4135 is over the clickable text. However, the mouse shape still indicates
4136 when the mouse is over clickable text. */);
4137 Vmouse_highlight = Qt;
4139 DEFVAR_LISP ("delete-frame-functions", &Vdelete_frame_functions,
4140 doc: /* Functions to be run before deleting a frame.
4141 The functions are run with one arg, the frame to be deleted.
4142 See `delete-frame'. */);
4143 Vdelete_frame_functions = Qnil;
4145 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4146 doc: /* Minibufferless frames use this frame's minibuffer.
4148 Emacs cannot create minibufferless frames unless this is set to an
4149 appropriate surrogate.
4151 Emacs consults this variable only when creating minibufferless
4152 frames; once the frame is created, it sticks with its assigned
4153 minibuffer, no matter what this variable is set to. This means that
4154 this variable doesn't necessarily say anything meaningful about the
4155 current set of frames, or where the minibuffer is currently being
4156 displayed.
4158 This variable is local to the current terminal and cannot be buffer-local. */);
4160 DEFVAR_BOOL ("focus-follows-mouse", &focus_follows_mouse,
4161 doc: /* Non-nil if window system changes focus when you move the mouse.
4162 You should set this variable to tell Emacs how your window manager
4163 handles focus, since there is no way in general for Emacs to find out
4164 automatically. */);
4165 #ifdef HAVE_WINDOW_SYSTEM
4166 #if defined(HAVE_NTGUI) || defined(MAC_OS)
4167 focus_follows_mouse = 0;
4168 #else
4169 focus_follows_mouse = 1;
4170 #endif
4171 #else
4172 focus_follows_mouse = 0;
4173 #endif
4175 staticpro (&Vframe_list);
4177 defsubr (&Sactive_minibuffer_window);
4178 defsubr (&Sframep);
4179 defsubr (&Sframe_live_p);
4180 defsubr (&Smake_terminal_frame);
4181 defsubr (&Shandle_switch_frame);
4182 defsubr (&Sselect_frame);
4183 defsubr (&Sselected_frame);
4184 defsubr (&Swindow_frame);
4185 defsubr (&Sframe_root_window);
4186 defsubr (&Sframe_first_window);
4187 defsubr (&Sframe_selected_window);
4188 defsubr (&Sset_frame_selected_window);
4189 defsubr (&Sframe_list);
4190 defsubr (&Snext_frame);
4191 defsubr (&Sprevious_frame);
4192 defsubr (&Sdelete_frame);
4193 defsubr (&Smouse_position);
4194 defsubr (&Smouse_pixel_position);
4195 defsubr (&Sset_mouse_position);
4196 defsubr (&Sset_mouse_pixel_position);
4197 #if 0
4198 defsubr (&Sframe_configuration);
4199 defsubr (&Srestore_frame_configuration);
4200 #endif
4201 defsubr (&Smake_frame_visible);
4202 defsubr (&Smake_frame_invisible);
4203 defsubr (&Siconify_frame);
4204 defsubr (&Sframe_visible_p);
4205 defsubr (&Svisible_frame_list);
4206 defsubr (&Sraise_frame);
4207 defsubr (&Slower_frame);
4208 defsubr (&Sredirect_frame_focus);
4209 defsubr (&Sframe_focus);
4210 defsubr (&Sframe_parameters);
4211 defsubr (&Sframe_parameter);
4212 defsubr (&Smodify_frame_parameters);
4213 defsubr (&Sframe_char_height);
4214 defsubr (&Sframe_char_width);
4215 defsubr (&Sframe_pixel_height);
4216 defsubr (&Sframe_pixel_width);
4217 defsubr (&Sset_frame_height);
4218 defsubr (&Sset_frame_width);
4219 defsubr (&Sset_frame_size);
4220 defsubr (&Sset_frame_position);
4222 #ifdef HAVE_WINDOW_SYSTEM
4223 defsubr (&Sx_get_resource);
4224 defsubr (&Sx_parse_geometry);
4225 #endif
4229 /* arch-tag: 7dbf2c69-9aad-45f8-8296-db893d6dd039
4230 (do not change this comment) */