Merge from emacs-24; up to 2012-04-30T11:57:47Z!sdl.web@gmail.com
[bpt/emacs.git] / src / frame.c
1 /* Generic frame functions.
2
3 Copyright (C) 1993-1995, 1997, 1999-2012 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
19
20 #include <config.h>
21
22 #include <stdio.h>
23 #include <ctype.h>
24 #include <errno.h>
25 #include <limits.h>
26 #include <setjmp.h>
27 #include "lisp.h"
28 #include "character.h"
29 #ifdef HAVE_X_WINDOWS
30 #include "xterm.h"
31 #endif
32 #ifdef WINDOWSNT
33 #include "w32term.h"
34 #endif
35 #ifdef HAVE_NS
36 #include "nsterm.h"
37 #endif
38 #include "buffer.h"
39 /* These help us bind and responding to switch-frame events. */
40 #include "commands.h"
41 #include "keyboard.h"
42 #include "frame.h"
43 #include "blockinput.h"
44 #include "termchar.h"
45 #include "termhooks.h"
46 #include "dispextern.h"
47 #include "window.h"
48 #include "font.h"
49 #ifdef HAVE_WINDOW_SYSTEM
50 #include "fontset.h"
51 #endif
52 #ifdef MSDOS
53 #include "msdos.h"
54 #include "dosfns.h"
55 #endif
56
57
58 #ifdef HAVE_WINDOW_SYSTEM
59
60 #endif
61
62 #ifdef HAVE_NS
63 Lisp_Object Qns_parse_geometry;
64 #endif
65
66 Lisp_Object Qframep, Qframe_live_p;
67 Lisp_Object Qicon, Qmodeline;
68 Lisp_Object Qonly;
69 Lisp_Object Qx, Qw32, Qmac, Qpc, Qns;
70 Lisp_Object Qvisible;
71 Lisp_Object Qdisplay_type;
72 static Lisp_Object Qbackground_mode;
73 Lisp_Object Qnoelisp;
74
75 static Lisp_Object Qx_frame_parameter;
76 Lisp_Object Qx_resource_name;
77 Lisp_Object Qterminal;
78 Lisp_Object Qterminal_live_p;
79
80 /* Frame parameters (set or reported). */
81
82 Lisp_Object Qauto_raise, Qauto_lower;
83 Lisp_Object Qborder_color, Qborder_width;
84 Lisp_Object Qcursor_color, Qcursor_type;
85 static Lisp_Object Qgeometry; /* Not used */
86 Lisp_Object Qheight, Qwidth;
87 Lisp_Object Qleft, Qright;
88 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
89 Lisp_Object Qtooltip;
90 Lisp_Object Qinternal_border_width;
91 Lisp_Object Qmouse_color;
92 Lisp_Object Qminibuffer;
93 Lisp_Object Qscroll_bar_width, Qvertical_scroll_bars;
94 Lisp_Object Qvisibility;
95 Lisp_Object Qscroll_bar_foreground, Qscroll_bar_background;
96 Lisp_Object Qscreen_gamma;
97 Lisp_Object Qline_spacing;
98 static Lisp_Object Quser_position, Quser_size;
99 Lisp_Object Qwait_for_wm;
100 static Lisp_Object Qwindow_id;
101 #ifdef HAVE_X_WINDOWS
102 static Lisp_Object Qouter_window_id;
103 #endif
104 Lisp_Object Qparent_id;
105 Lisp_Object Qtitle, Qname;
106 static Lisp_Object Qexplicit_name;
107 Lisp_Object Qunsplittable;
108 Lisp_Object Qmenu_bar_lines, Qtool_bar_lines, Qtool_bar_position;
109 Lisp_Object Qleft_fringe, Qright_fringe;
110 Lisp_Object Qbuffer_predicate;
111 static Lisp_Object Qbuffer_list, Qburied_buffer_list;
112 Lisp_Object Qtty_color_mode;
113 Lisp_Object Qtty, Qtty_type;
114
115 Lisp_Object Qfullscreen, Qfullwidth, Qfullheight, Qfullboth, Qmaximized;
116 Lisp_Object Qsticky;
117 Lisp_Object Qfont_backend;
118 Lisp_Object Qalpha;
119
120 Lisp_Object Qface_set_after_frame_default;
121
122 static Lisp_Object Qdelete_frame_functions;
123
124 #ifdef HAVE_WINDOW_SYSTEM
125 static void x_report_frame_params (struct frame *, Lisp_Object *);
126 #endif
127
128 \f
129 static void
130 set_menu_bar_lines_1 (Lisp_Object window, int n)
131 {
132 struct window *w = XWINDOW (window);
133
134 w->last_modified = 0;
135 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
136 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
137
138 /* Handle just the top child in a vertical split. */
139 if (!NILP (w->vchild))
140 set_menu_bar_lines_1 (w->vchild, n);
141
142 /* Adjust all children in a horizontal split. */
143 for (window = w->hchild; !NILP (window); window = w->next)
144 {
145 w = XWINDOW (window);
146 set_menu_bar_lines_1 (window, n);
147 }
148 }
149
150 void
151 set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
152 {
153 int nlines;
154 int olines = FRAME_MENU_BAR_LINES (f);
155
156 /* Right now, menu bars don't work properly in minibuf-only frames;
157 most of the commands try to apply themselves to the minibuffer
158 frame itself, and get an error because you can't switch buffers
159 in or split the minibuffer window. */
160 if (FRAME_MINIBUF_ONLY_P (f))
161 return;
162
163 if (TYPE_RANGED_INTEGERP (int, value))
164 nlines = XINT (value);
165 else
166 nlines = 0;
167
168 if (nlines != olines)
169 {
170 windows_or_buffers_changed++;
171 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
172 FRAME_MENU_BAR_LINES (f) = nlines;
173 set_menu_bar_lines_1 (f->root_window, nlines - olines);
174 adjust_glyphs (f);
175 }
176 }
177 \f
178 Lisp_Object Vframe_list;
179
180 \f
181 DEFUN ("framep", Fframep, Sframep, 1, 1, 0,
182 doc: /* Return non-nil if OBJECT is a frame.
183 Value is:
184 t for a termcap frame (a character-only terminal),
185 'x' for an Emacs frame that is really an X window,
186 'w32' for an Emacs frame that is a window on MS-Windows display,
187 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
188 'pc' for a direct-write MS-DOS frame.
189 See also `frame-live-p'. */)
190 (Lisp_Object object)
191 {
192 if (!FRAMEP (object))
193 return Qnil;
194 switch (XFRAME (object)->output_method)
195 {
196 case output_initial: /* The initial frame is like a termcap frame. */
197 case output_termcap:
198 return Qt;
199 case output_x_window:
200 return Qx;
201 case output_w32:
202 return Qw32;
203 case output_msdos_raw:
204 return Qpc;
205 case output_mac:
206 return Qmac;
207 case output_ns:
208 return Qns;
209 default:
210 abort ();
211 }
212 }
213
214 DEFUN ("frame-live-p", Fframe_live_p, Sframe_live_p, 1, 1, 0,
215 doc: /* Return non-nil if OBJECT is a frame which has not been deleted.
216 Value is nil if OBJECT is not a live frame. If object is a live
217 frame, the return value indicates what sort of terminal device it is
218 displayed on. See the documentation of `framep' for possible
219 return values. */)
220 (Lisp_Object object)
221 {
222 return ((FRAMEP (object)
223 && FRAME_LIVE_P (XFRAME (object)))
224 ? Fframep (object)
225 : Qnil);
226 }
227
228 DEFUN ("window-system", Fwindow_system, Swindow_system, 0, 1, 0,
229 doc: /* The name of the window system that FRAME is displaying through.
230 The value is a symbol:
231 nil for a termcap frame (a character-only terminal),
232 'x' for an Emacs frame that is really an X window,
233 'w32' for an Emacs frame that is a window on MS-Windows display,
234 'ns' for an Emacs frame on a GNUstep or Macintosh Cocoa display,
235 'pc' for a direct-write MS-DOS frame.
236
237 FRAME defaults to the currently selected frame.
238
239 Use of this function as a predicate is deprecated. Instead,
240 use `display-graphic-p' or any of the other `display-*-p'
241 predicates which report frame's specific UI-related capabilities. */)
242 (Lisp_Object frame)
243 {
244 Lisp_Object type;
245 if (NILP (frame))
246 frame = selected_frame;
247
248 type = Fframep (frame);
249
250 if (NILP (type))
251 wrong_type_argument (Qframep, frame);
252
253 if (EQ (type, Qt))
254 return Qnil;
255 else
256 return type;
257 }
258
259 struct frame *
260 make_frame (int mini_p)
261 {
262 Lisp_Object frame;
263 register struct frame *f;
264 register Lisp_Object root_window;
265 register Lisp_Object mini_window;
266
267 f = allocate_frame ();
268 XSETFRAME (frame, f);
269
270 /* Initialize Lisp data. Note that allocate_frame initializes all
271 Lisp data to nil, so do it only for slots which should not be nil. */
272 f->tool_bar_position = Qtop;
273
274 /* Initialize non-Lisp data. Note that allocate_frame zeroes out all
275 non-Lisp data, so do it only for slots which should not be zero.
276 To avoid subtle bugs and for the sake of readability, it's better to
277 initialize enum members explicitly even if their values are zero. */
278 f->wants_modeline = 1;
279 f->garbaged = 1;
280 f->has_minibuffer = mini_p;
281 f->vertical_scroll_bar_type = vertical_scroll_bar_none;
282 f->column_width = 1; /* !FRAME_WINDOW_P value */
283 f->line_height = 1; /* !FRAME_WINDOW_P value */
284 #ifdef HAVE_WINDOW_SYSTEM
285 f->want_fullscreen = FULLSCREEN_NONE;
286 #endif
287
288 root_window = make_window ();
289 if (mini_p)
290 {
291 mini_window = make_window ();
292 XWINDOW (root_window)->next = mini_window;
293 XWINDOW (mini_window)->prev = root_window;
294 XWINDOW (mini_window)->mini = 1;
295 XWINDOW (mini_window)->frame = frame;
296 f->minibuffer_window = mini_window;
297 }
298 else
299 {
300 mini_window = Qnil;
301 XWINDOW (root_window)->next = Qnil;
302 f->minibuffer_window = Qnil;
303 }
304
305 XWINDOW (root_window)->frame = frame;
306
307 /* 10 is arbitrary,
308 just so that there is "something there."
309 Correct size will be set up later with change_frame_size. */
310
311 SET_FRAME_COLS (f, 10);
312 FRAME_LINES (f) = 10;
313
314 XSETFASTINT (XWINDOW (root_window)->total_cols, 10);
315 XSETFASTINT (XWINDOW (root_window)->total_lines, (mini_p ? 9 : 10));
316
317 if (mini_p)
318 {
319 XSETFASTINT (XWINDOW (mini_window)->total_cols, 10);
320 XSETFASTINT (XWINDOW (mini_window)->top_line, 9);
321 XSETFASTINT (XWINDOW (mini_window)->total_lines, 1);
322 }
323
324 /* Choose a buffer for the frame's root window. */
325 {
326 Lisp_Object buf;
327
328 XWINDOW (root_window)->buffer = Qt;
329 buf = Fcurrent_buffer ();
330 /* If buf is a 'hidden' buffer (i.e. one whose name starts with
331 a space), try to find another one. */
332 if (SREF (Fbuffer_name (buf), 0) == ' ')
333 buf = other_buffer_safely (buf);
334
335 /* Use set_window_buffer, not Fset_window_buffer, and don't let
336 hooks be run by it. The reason is that the whole frame/window
337 arrangement is not yet fully initialized at this point. Windows
338 don't have the right size, glyph matrices aren't initialized
339 etc. Running Lisp functions at this point surely ends in a
340 SEGV. */
341 set_window_buffer (root_window, buf, 0, 0);
342 f->buffer_list = Fcons (buf, Qnil);
343 }
344
345 if (mini_p)
346 {
347 XWINDOW (mini_window)->buffer = Qt;
348 set_window_buffer (mini_window,
349 (NILP (Vminibuffer_list)
350 ? get_minibuffer (0)
351 : Fcar (Vminibuffer_list)),
352 0, 0);
353 }
354
355 f->root_window = root_window;
356 f->selected_window = root_window;
357 /* Make sure this window seems more recently used than
358 a newly-created, never-selected window. */
359 XWINDOW (f->selected_window)->use_time = ++window_select_count;
360
361 return f;
362 }
363 \f
364 #ifdef HAVE_WINDOW_SYSTEM
365 /* Make a frame using a separate minibuffer window on another frame.
366 MINI_WINDOW is the minibuffer window to use. nil means use the
367 default (the global minibuffer). */
368
369 struct frame *
370 make_frame_without_minibuffer (register Lisp_Object mini_window, KBOARD *kb, Lisp_Object display)
371 {
372 register struct frame *f;
373 struct gcpro gcpro1;
374
375 if (!NILP (mini_window))
376 CHECK_LIVE_WINDOW (mini_window);
377
378 if (!NILP (mini_window)
379 && FRAME_KBOARD (XFRAME (XWINDOW (mini_window)->frame)) != kb)
380 error ("Frame and minibuffer must be on the same terminal");
381
382 /* Make a frame containing just a root window. */
383 f = make_frame (0);
384
385 if (NILP (mini_window))
386 {
387 /* Use default-minibuffer-frame if possible. */
388 if (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
389 || ! FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame))))
390 {
391 Lisp_Object frame_dummy;
392
393 XSETFRAME (frame_dummy, f);
394 GCPRO1 (frame_dummy);
395 /* If there's no minibuffer frame to use, create one. */
396 KVAR (kb, Vdefault_minibuffer_frame) =
397 call1 (intern ("make-initial-minibuffer-frame"), display);
398 UNGCPRO;
399 }
400
401 mini_window = XFRAME (KVAR (kb, Vdefault_minibuffer_frame))->minibuffer_window;
402 }
403
404 f->minibuffer_window = mini_window;
405
406 /* Make the chosen minibuffer window display the proper minibuffer,
407 unless it is already showing a minibuffer. */
408 if (NILP (Fmemq (XWINDOW (mini_window)->buffer, Vminibuffer_list)))
409 Fset_window_buffer (mini_window,
410 (NILP (Vminibuffer_list)
411 ? get_minibuffer (0)
412 : Fcar (Vminibuffer_list)), Qnil);
413 return f;
414 }
415
416 /* Make a frame containing only a minibuffer window. */
417
418 struct frame *
419 make_minibuffer_frame (void)
420 {
421 /* First make a frame containing just a root window, no minibuffer. */
422
423 register struct frame *f = make_frame (0);
424 register Lisp_Object mini_window;
425 register Lisp_Object frame;
426
427 XSETFRAME (frame, f);
428
429 f->auto_raise = 0;
430 f->auto_lower = 0;
431 f->no_split = 1;
432 f->wants_modeline = 0;
433 f->has_minibuffer = 1;
434
435 /* Now label the root window as also being the minibuffer.
436 Avoid infinite looping on the window chain by marking next pointer
437 as nil. */
438
439 mini_window = f->minibuffer_window = f->root_window;
440 XWINDOW (mini_window)->mini = 1;
441 XWINDOW (mini_window)->next = Qnil;
442 XWINDOW (mini_window)->prev = Qnil;
443 XWINDOW (mini_window)->frame = frame;
444
445 /* Put the proper buffer in that window. */
446
447 Fset_window_buffer (mini_window,
448 (NILP (Vminibuffer_list)
449 ? get_minibuffer (0)
450 : Fcar (Vminibuffer_list)), Qnil);
451 return f;
452 }
453 #endif /* HAVE_WINDOW_SYSTEM */
454 \f
455 /* Construct a frame that refers to a terminal. */
456
457 static printmax_t tty_frame_count;
458
459 struct frame *
460 make_initial_frame (void)
461 {
462 struct frame *f;
463 struct terminal *terminal;
464 Lisp_Object frame;
465
466 eassert (initial_kboard);
467
468 /* The first call must initialize Vframe_list. */
469 if (! (NILP (Vframe_list) || CONSP (Vframe_list)))
470 Vframe_list = Qnil;
471
472 terminal = init_initial_terminal ();
473
474 f = make_frame (1);
475 XSETFRAME (frame, f);
476
477 Vframe_list = Fcons (frame, Vframe_list);
478
479 tty_frame_count = 1;
480 f->name = make_pure_c_string ("F1");
481
482 f->visible = 1;
483 f->async_visible = 1;
484
485 f->output_method = terminal->type;
486 f->terminal = terminal;
487 f->terminal->reference_count++;
488 f->output_data.nothing = 0;
489
490 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
491 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
492
493 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
494 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
495
496 /* The default value of menu-bar-mode is t. */
497 set_menu_bar_lines (f, make_number (1), Qnil);
498
499 if (!noninteractive)
500 init_frame_faces (f);
501
502 return f;
503 }
504
505
506 static struct frame *
507 make_terminal_frame (struct terminal *terminal)
508 {
509 register struct frame *f;
510 Lisp_Object frame;
511 char name[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
512
513 if (!terminal->name)
514 error ("Terminal is not live, can't create new frames on it");
515
516 f = make_frame (1);
517
518 XSETFRAME (frame, f);
519 Vframe_list = Fcons (frame, Vframe_list);
520
521 tty_frame_count++;
522 sprintf (name, "F%"pMd, tty_frame_count);
523 f->name = build_string (name);
524
525 f->visible = 1; /* FRAME_SET_VISIBLE wd set frame_garbaged. */
526 f->async_visible = 1; /* Don't let visible be cleared later. */
527 f->terminal = terminal;
528 f->terminal->reference_count++;
529 #ifdef MSDOS
530 f->output_data.tty->display_info = &the_only_display_info;
531 if (!inhibit_window_system
532 && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame))
533 || XFRAME (selected_frame)->output_method == output_msdos_raw))
534 f->output_method = output_msdos_raw;
535 else
536 f->output_method = output_termcap;
537 #else /* not MSDOS */
538 f->output_method = output_termcap;
539 create_tty_output (f);
540 FRAME_FOREGROUND_PIXEL (f) = FACE_TTY_DEFAULT_FG_COLOR;
541 FRAME_BACKGROUND_PIXEL (f) = FACE_TTY_DEFAULT_BG_COLOR;
542 #endif /* not MSDOS */
543
544 FRAME_CAN_HAVE_SCROLL_BARS (f) = 0;
545 FRAME_VERTICAL_SCROLL_BAR_TYPE (f) = vertical_scroll_bar_none;
546 FRAME_MENU_BAR_LINES(f) = NILP (Vmenu_bar_mode) ? 0 : 1;
547
548 /* Set the top frame to the newly created frame. */
549 if (FRAMEP (FRAME_TTY (f)->top_frame)
550 && FRAME_LIVE_P (XFRAME (FRAME_TTY (f)->top_frame)))
551 XFRAME (FRAME_TTY (f)->top_frame)->async_visible = 2; /* obscured */
552
553 FRAME_TTY (f)->top_frame = frame;
554
555 if (!noninteractive)
556 init_frame_faces (f);
557
558 return f;
559 }
560
561 /* Get a suitable value for frame parameter PARAMETER for a newly
562 created frame, based on (1) the user-supplied frame parameter
563 alist SUPPLIED_PARMS, and (2) CURRENT_VALUE. */
564
565 static Lisp_Object
566 get_future_frame_param (Lisp_Object parameter,
567 Lisp_Object supplied_parms,
568 char *current_value)
569 {
570 Lisp_Object result;
571
572 result = Fassq (parameter, supplied_parms);
573 if (NILP (result))
574 result = Fassq (parameter, XFRAME (selected_frame)->param_alist);
575 if (NILP (result) && current_value != NULL)
576 result = build_string (current_value);
577 if (!NILP (result) && !STRINGP (result))
578 result = XCDR (result);
579 if (NILP (result) || !STRINGP (result))
580 result = Qnil;
581
582 return result;
583 }
584
585 DEFUN ("make-terminal-frame", Fmake_terminal_frame, Smake_terminal_frame,
586 1, 1, 0,
587 doc: /* Create an additional terminal frame, possibly on another terminal.
588 This function takes one argument, an alist specifying frame parameters.
589
590 You can create multiple frames on a single text terminal, but only one
591 of them (the selected terminal frame) is actually displayed.
592
593 In practice, generally you don't need to specify any parameters,
594 except when you want to create a new frame on another terminal.
595 In that case, the `tty' parameter specifies the device file to open,
596 and the `tty-type' parameter specifies the terminal type. Example:
597
598 (make-terminal-frame '((tty . "/dev/pts/5") (tty-type . "xterm")))
599
600 Note that changing the size of one terminal frame automatically
601 affects all frames on the same terminal device. */)
602 (Lisp_Object parms)
603 {
604 struct frame *f;
605 struct terminal *t = NULL;
606 Lisp_Object frame, tem;
607 struct frame *sf = SELECTED_FRAME ();
608
609 #ifdef MSDOS
610 if (sf->output_method != output_msdos_raw
611 && sf->output_method != output_termcap)
612 abort ();
613 #else /* not MSDOS */
614
615 #ifdef WINDOWSNT /* This should work now! */
616 if (sf->output_method != output_termcap)
617 error ("Not using an ASCII terminal now; cannot make a new ASCII frame");
618 #endif
619 #endif /* not MSDOS */
620
621 {
622 Lisp_Object terminal;
623
624 terminal = Fassq (Qterminal, parms);
625 if (!NILP (terminal))
626 {
627 terminal = XCDR (terminal);
628 t = get_terminal (terminal, 1);
629 }
630 #ifdef MSDOS
631 if (t && t != the_only_display_info.terminal)
632 /* msdos.c assumes a single tty_display_info object. */
633 error ("Multiple terminals are not supported on this platform");
634 if (!t)
635 t = the_only_display_info.terminal;
636 #endif
637 }
638
639 if (!t)
640 {
641 char *name = 0, *type = 0;
642 Lisp_Object tty, tty_type;
643
644 tty = get_future_frame_param
645 (Qtty, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
646 ? FRAME_TTY (XFRAME (selected_frame))->name
647 : NULL));
648 if (!NILP (tty))
649 {
650 name = (char *) alloca (SBYTES (tty) + 1);
651 strncpy (name, SSDATA (tty), SBYTES (tty));
652 name[SBYTES (tty)] = 0;
653 }
654
655 tty_type = get_future_frame_param
656 (Qtty_type, parms, (FRAME_TERMCAP_P (XFRAME (selected_frame))
657 ? FRAME_TTY (XFRAME (selected_frame))->type
658 : NULL));
659 if (!NILP (tty_type))
660 {
661 type = (char *) alloca (SBYTES (tty_type) + 1);
662 strncpy (type, SSDATA (tty_type), SBYTES (tty_type));
663 type[SBYTES (tty_type)] = 0;
664 }
665
666 t = init_tty (name, type, 0); /* Errors are not fatal. */
667 }
668
669 f = make_terminal_frame (t);
670
671 {
672 int width, height;
673 get_tty_size (fileno (FRAME_TTY (f)->input), &width, &height);
674 change_frame_size (f, height, width, 0, 0, 0);
675 }
676
677 adjust_glyphs (f);
678 calculate_costs (f);
679 XSETFRAME (frame, f);
680 Fmodify_frame_parameters (frame, parms);
681 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty_type,
682 build_string (t->display_info.tty->type)),
683 Qnil));
684 if (t->display_info.tty->name != NULL)
685 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty,
686 build_string (t->display_info.tty->name)),
687 Qnil));
688 else
689 Fmodify_frame_parameters (frame, Fcons (Fcons (Qtty, Qnil), Qnil));
690
691 /* Make the frame face alist be frame-specific, so that each
692 frame could change its face definitions independently. */
693 f->face_alist = Fcopy_alist (sf->face_alist);
694 /* Simple Fcopy_alist isn't enough, because we need the contents of
695 the vectors which are the CDRs of associations in face_alist to
696 be copied as well. */
697 for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
698 XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
699 return frame;
700 }
701
702 \f
703 /* Perform the switch to frame FRAME.
704
705 If FRAME is a switch-frame event `(switch-frame FRAME1)', use
706 FRAME1 as frame.
707
708 If TRACK is non-zero and the frame that currently has the focus
709 redirects its focus to the selected frame, redirect that focused
710 frame's focus to FRAME instead.
711
712 FOR_DELETION non-zero means that the selected frame is being
713 deleted, which includes the possibility that the frame's terminal
714 is dead.
715
716 The value of NORECORD is passed as argument to Fselect_window. */
717
718 Lisp_Object
719 do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object norecord)
720 {
721 struct frame *sf = SELECTED_FRAME ();
722
723 /* If FRAME is a switch-frame event, extract the frame we should
724 switch to. */
725 if (CONSP (frame)
726 && EQ (XCAR (frame), Qswitch_frame)
727 && CONSP (XCDR (frame)))
728 frame = XCAR (XCDR (frame));
729
730 /* This used to say CHECK_LIVE_FRAME, but apparently it's possible for
731 a switch-frame event to arrive after a frame is no longer live,
732 especially when deleting the initial frame during startup. */
733 CHECK_FRAME (frame);
734 if (! FRAME_LIVE_P (XFRAME (frame)))
735 return Qnil;
736
737 if (sf == XFRAME (frame))
738 return frame;
739
740 /* This is too greedy; it causes inappropriate focus redirection
741 that's hard to get rid of. */
742 #if 0
743 /* If a frame's focus has been redirected toward the currently
744 selected frame, we should change the redirection to point to the
745 newly selected frame. This means that if the focus is redirected
746 from a minibufferless frame to a surrogate minibuffer frame, we
747 can use `other-window' to switch between all the frames using
748 that minibuffer frame, and the focus redirection will follow us
749 around. */
750 if (track)
751 {
752 Lisp_Object tail;
753
754 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
755 {
756 Lisp_Object focus;
757
758 if (!FRAMEP (XCAR (tail)))
759 abort ();
760
761 focus = FRAME_FOCUS_FRAME (XFRAME (XCAR (tail)));
762
763 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
764 Fredirect_frame_focus (XCAR (tail), frame);
765 }
766 }
767 #else /* ! 0 */
768 /* Instead, apply it only to the frame we're pointing to. */
769 #ifdef HAVE_WINDOW_SYSTEM
770 if (track && FRAME_WINDOW_P (XFRAME (frame)))
771 {
772 Lisp_Object focus, xfocus;
773
774 xfocus = x_get_focus_frame (XFRAME (frame));
775 if (FRAMEP (xfocus))
776 {
777 focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
778 if (FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
779 Fredirect_frame_focus (xfocus, frame);
780 }
781 }
782 #endif /* HAVE_X_WINDOWS */
783 #endif /* ! 0 */
784
785 if (!for_deletion && FRAME_HAS_MINIBUF_P (sf))
786 resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1);
787
788 if (FRAME_TERMCAP_P (XFRAME (frame)) || FRAME_MSDOS_P (XFRAME (frame)))
789 {
790 if (FRAMEP (FRAME_TTY (XFRAME (frame))->top_frame))
791 /* Mark previously displayed frame as now obscured. */
792 XFRAME (FRAME_TTY (XFRAME (frame))->top_frame)->async_visible = 2;
793 XFRAME (frame)->async_visible = 1;
794 FRAME_TTY (XFRAME (frame))->top_frame = frame;
795 }
796
797 selected_frame = frame;
798 if (! FRAME_MINIBUF_ONLY_P (XFRAME (selected_frame)))
799 last_nonminibuf_frame = XFRAME (selected_frame);
800
801 Fselect_window (XFRAME (frame)->selected_window, norecord);
802
803 /* We want to make sure that the next event generates a frame-switch
804 event to the appropriate frame. This seems kludgy to me, but
805 before you take it out, make sure that evaluating something like
806 (select-window (frame-root-window (new-frame))) doesn't end up
807 with your typing being interpreted in the new frame instead of
808 the one you're actually typing in. */
809 internal_last_event_frame = Qnil;
810
811 return frame;
812 }
813
814 DEFUN ("select-frame", Fselect_frame, Sselect_frame, 1, 2, "e",
815 doc: /* Select FRAME.
816 Subsequent editing commands apply to its selected window.
817 Optional argument NORECORD means to neither change the order of
818 recently selected windows nor the buffer list.
819
820 The selection of FRAME lasts until the next time the user does
821 something to select a different frame, or until the next time
822 this function is called. If you are using a window system, the
823 previously selected frame may be restored as the selected frame
824 when returning to the command loop, because it still may have
825 the window system's input focus. On a text terminal, the next
826 redisplay will display FRAME.
827
828 This function returns FRAME, or nil if FRAME has been deleted. */)
829 (Lisp_Object frame, Lisp_Object norecord)
830 {
831 return do_switch_frame (frame, 1, 0, norecord);
832 }
833
834
835 DEFUN ("handle-switch-frame", Fhandle_switch_frame, Shandle_switch_frame, 1, 1, "e",
836 doc: /* Handle a switch-frame event EVENT.
837 Switch-frame events are usually bound to this function.
838 A switch-frame event tells Emacs that the window manager has requested
839 that the user's events be directed to the frame mentioned in the event.
840 This function selects the selected window of the frame of EVENT.
841
842 If EVENT is frame object, handle it as if it were a switch-frame event
843 to that frame. */)
844 (Lisp_Object event)
845 {
846 /* Preserve prefix arg that the command loop just cleared. */
847 KVAR (current_kboard, Vprefix_arg) = Vcurrent_prefix_arg;
848 Frun_hooks (1, &Qmouse_leave_buffer_hook);
849 return do_switch_frame (event, 0, 0, Qnil);
850 }
851
852 DEFUN ("selected-frame", Fselected_frame, Sselected_frame, 0, 0, 0,
853 doc: /* Return the frame that is now selected. */)
854 (void)
855 {
856 return selected_frame;
857 }
858 \f
859 DEFUN ("frame-list", Fframe_list, Sframe_list,
860 0, 0, 0,
861 doc: /* Return a list of all live frames. */)
862 (void)
863 {
864 Lisp_Object frames;
865 frames = Fcopy_sequence (Vframe_list);
866 #ifdef HAVE_WINDOW_SYSTEM
867 if (FRAMEP (tip_frame))
868 frames = Fdelq (tip_frame, frames);
869 #endif
870 return frames;
871 }
872
873 /* Return the next frame in the frame list after FRAME.
874 If MINIBUF is nil, exclude minibuffer-only frames.
875 If MINIBUF is a window, include only its own frame
876 and any frame now using that window as the minibuffer.
877 If MINIBUF is `visible', include all visible frames.
878 If MINIBUF is 0, include all visible and iconified frames.
879 Otherwise, include all frames. */
880
881 static Lisp_Object
882 next_frame (Lisp_Object frame, Lisp_Object minibuf)
883 {
884 Lisp_Object tail;
885 int passed = 0;
886
887 /* There must always be at least one frame in Vframe_list. */
888 if (! CONSP (Vframe_list))
889 abort ();
890
891 /* If this frame is dead, it won't be in Vframe_list, and we'll loop
892 forever. Forestall that. */
893 CHECK_LIVE_FRAME (frame);
894
895 while (1)
896 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
897 {
898 Lisp_Object f;
899
900 f = XCAR (tail);
901
902 if (passed
903 && ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
904 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
905 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
906 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame)))))
907 {
908 /* Decide whether this frame is eligible to be returned. */
909
910 /* If we've looped all the way around without finding any
911 eligible frames, return the original frame. */
912 if (EQ (f, frame))
913 return f;
914
915 /* Let minibuf decide if this frame is acceptable. */
916 if (NILP (minibuf))
917 {
918 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
919 return f;
920 }
921 else if (EQ (minibuf, Qvisible))
922 {
923 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
924 if (FRAME_VISIBLE_P (XFRAME (f)))
925 return f;
926 }
927 else if (INTEGERP (minibuf) && XINT (minibuf) == 0)
928 {
929 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
930 if (FRAME_VISIBLE_P (XFRAME (f))
931 || FRAME_ICONIFIED_P (XFRAME (f)))
932 return f;
933 }
934 else if (WINDOWP (minibuf))
935 {
936 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
937 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
938 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
939 FRAME_FOCUS_FRAME (XFRAME (f))))
940 return f;
941 }
942 else
943 return f;
944 }
945
946 if (EQ (frame, f))
947 passed++;
948 }
949 }
950
951 /* Return the previous frame in the frame list before FRAME.
952 If MINIBUF is nil, exclude minibuffer-only frames.
953 If MINIBUF is a window, include only its own frame
954 and any frame now using that window as the minibuffer.
955 If MINIBUF is `visible', include all visible frames.
956 If MINIBUF is 0, include all visible and iconified frames.
957 Otherwise, include all frames. */
958
959 static Lisp_Object
960 prev_frame (Lisp_Object frame, Lisp_Object minibuf)
961 {
962 Lisp_Object tail;
963 Lisp_Object prev;
964
965 /* There must always be at least one frame in Vframe_list. */
966 if (! CONSP (Vframe_list))
967 abort ();
968
969 prev = Qnil;
970 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
971 {
972 Lisp_Object f;
973
974 f = XCAR (tail);
975 if (!FRAMEP (f))
976 abort ();
977
978 if (EQ (frame, f) && !NILP (prev))
979 return prev;
980
981 if ((!FRAME_TERMCAP_P (XFRAME (f)) && !FRAME_TERMCAP_P (XFRAME (frame))
982 && FRAME_KBOARD (XFRAME (f)) == FRAME_KBOARD (XFRAME (frame)))
983 || (FRAME_TERMCAP_P (XFRAME (f)) && FRAME_TERMCAP_P (XFRAME (frame))
984 && FRAME_TTY (XFRAME (f)) == FRAME_TTY (XFRAME (frame))))
985 {
986 /* Decide whether this frame is eligible to be returned,
987 according to minibuf. */
988 if (NILP (minibuf))
989 {
990 if (! FRAME_MINIBUF_ONLY_P (XFRAME (f)))
991 prev = f;
992 }
993 else if (WINDOWP (minibuf))
994 {
995 if (EQ (FRAME_MINIBUF_WINDOW (XFRAME (f)), minibuf)
996 || EQ (WINDOW_FRAME (XWINDOW (minibuf)), f)
997 || EQ (WINDOW_FRAME (XWINDOW (minibuf)),
998 FRAME_FOCUS_FRAME (XFRAME (f))))
999 prev = f;
1000 }
1001 else if (EQ (minibuf, Qvisible))
1002 {
1003 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1004 if (FRAME_VISIBLE_P (XFRAME (f)))
1005 prev = f;
1006 }
1007 else if (XFASTINT (minibuf) == 0)
1008 {
1009 FRAME_SAMPLE_VISIBILITY (XFRAME (f));
1010 if (FRAME_VISIBLE_P (XFRAME (f))
1011 || FRAME_ICONIFIED_P (XFRAME (f)))
1012 prev = f;
1013 }
1014 else
1015 prev = f;
1016 }
1017 }
1018
1019 /* We've scanned the entire list. */
1020 if (NILP (prev))
1021 /* We went through the whole frame list without finding a single
1022 acceptable frame. Return the original frame. */
1023 return frame;
1024 else
1025 /* There were no acceptable frames in the list before FRAME; otherwise,
1026 we would have returned directly from the loop. Since PREV is the last
1027 acceptable frame in the list, return it. */
1028 return prev;
1029 }
1030
1031
1032 DEFUN ("next-frame", Fnext_frame, Snext_frame, 0, 2, 0,
1033 doc: /* Return the next frame in the frame list after FRAME.
1034 It considers only frames on the same terminal as FRAME.
1035 By default, skip minibuffer-only frames.
1036 If omitted, FRAME defaults to the selected frame.
1037 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1038 If MINIFRAME is a window, include only its own frame
1039 and any frame now using that window as the minibuffer.
1040 If MINIFRAME is `visible', include all visible frames.
1041 If MINIFRAME is 0, include all visible and iconified frames.
1042 Otherwise, include all frames. */)
1043 (Lisp_Object frame, Lisp_Object miniframe)
1044 {
1045 if (NILP (frame))
1046 frame = selected_frame;
1047
1048 CHECK_LIVE_FRAME (frame);
1049 return next_frame (frame, miniframe);
1050 }
1051
1052 DEFUN ("previous-frame", Fprevious_frame, Sprevious_frame, 0, 2, 0,
1053 doc: /* Return the previous frame in the frame list before FRAME.
1054 It considers only frames on the same terminal as FRAME.
1055 By default, skip minibuffer-only frames.
1056 If omitted, FRAME defaults to the selected frame.
1057 If optional argument MINIFRAME is nil, exclude minibuffer-only frames.
1058 If MINIFRAME is a window, include only its own frame
1059 and any frame now using that window as the minibuffer.
1060 If MINIFRAME is `visible', include all visible frames.
1061 If MINIFRAME is 0, include all visible and iconified frames.
1062 Otherwise, include all frames. */)
1063 (Lisp_Object frame, Lisp_Object miniframe)
1064 {
1065 if (NILP (frame))
1066 frame = selected_frame;
1067 CHECK_LIVE_FRAME (frame);
1068 return prev_frame (frame, miniframe);
1069 }
1070 \f
1071 /* Return 1 if it is ok to delete frame F;
1072 0 if all frames aside from F are invisible.
1073 (Exception: if F is the terminal frame, and we are using X, return 1.) */
1074
1075 static int
1076 other_visible_frames (FRAME_PTR f)
1077 {
1078 Lisp_Object frames;
1079
1080 for (frames = Vframe_list; CONSP (frames); frames = XCDR (frames))
1081 {
1082 Lisp_Object this = XCAR (frames);
1083 if (f == XFRAME (this))
1084 continue;
1085
1086 /* Verify that we can still talk to the frame's X window,
1087 and note any recent change in visibility. */
1088 #ifdef HAVE_WINDOW_SYSTEM
1089 if (FRAME_WINDOW_P (XFRAME (this)))
1090 {
1091 x_sync (XFRAME (this));
1092 FRAME_SAMPLE_VISIBILITY (XFRAME (this));
1093 }
1094 #endif
1095
1096 if (FRAME_VISIBLE_P (XFRAME (this))
1097 || FRAME_ICONIFIED_P (XFRAME (this))
1098 /* Allow deleting the terminal frame when at least one X
1099 frame exists. */
1100 || (FRAME_WINDOW_P (XFRAME (this)) && !FRAME_WINDOW_P (f)))
1101 return 1;
1102 }
1103 return 0;
1104 }
1105
1106 /* Delete FRAME. When FORCE equals Qnoelisp, delete FRAME
1107 unconditionally. x_connection_closed and delete_terminal use
1108 this. Any other value of FORCE implements the semantics
1109 described for Fdelete_frame. */
1110 Lisp_Object
1111 delete_frame (Lisp_Object frame, Lisp_Object force)
1112 {
1113 struct frame *f;
1114 struct frame *sf = SELECTED_FRAME ();
1115 struct kboard *kb;
1116
1117 int minibuffer_selected, tooltip_frame;
1118
1119 if (EQ (frame, Qnil))
1120 {
1121 f = sf;
1122 XSETFRAME (frame, f);
1123 }
1124 else
1125 {
1126 CHECK_FRAME (frame);
1127 f = XFRAME (frame);
1128 }
1129
1130 if (! FRAME_LIVE_P (f))
1131 return Qnil;
1132
1133 if (NILP (force) && !other_visible_frames (f))
1134 error ("Attempt to delete the sole visible or iconified frame");
1135
1136 /* x_connection_closed must have set FORCE to `noelisp' in order
1137 to delete the last frame, if it is gone. */
1138 if (NILP (XCDR (Vframe_list)) && !EQ (force, Qnoelisp))
1139 error ("Attempt to delete the only frame");
1140
1141 /* Does this frame have a minibuffer, and is it the surrogate
1142 minibuffer for any other frame? */
1143 if (FRAME_HAS_MINIBUF_P (XFRAME (frame)))
1144 {
1145 Lisp_Object frames;
1146
1147 for (frames = Vframe_list;
1148 CONSP (frames);
1149 frames = XCDR (frames))
1150 {
1151 Lisp_Object this;
1152 this = XCAR (frames);
1153
1154 if (! EQ (this, frame)
1155 && EQ (frame,
1156 WINDOW_FRAME (XWINDOW
1157 (FRAME_MINIBUF_WINDOW (XFRAME (this))))))
1158 {
1159 /* If we MUST delete this frame, delete the other first.
1160 But do this only if FORCE equals `noelisp'. */
1161 if (EQ (force, Qnoelisp))
1162 delete_frame (this, Qnoelisp);
1163 else
1164 error ("Attempt to delete a surrogate minibuffer frame");
1165 }
1166 }
1167 }
1168
1169 tooltip_frame = !NILP (Fframe_parameter (frame, intern ("tooltip")));
1170
1171 /* Run `delete-frame-functions' unless FORCE is `noelisp' or
1172 frame is a tooltip. FORCE is set to `noelisp' when handling
1173 a disconnect from the terminal, so we don't dare call Lisp
1174 code. */
1175 if (NILP (Vrun_hooks) || tooltip_frame)
1176 ;
1177 else if (EQ (force, Qnoelisp))
1178 pending_funcalls
1179 = Fcons (list3 (Qrun_hook_with_args, Qdelete_frame_functions, frame),
1180 pending_funcalls);
1181 else
1182 {
1183 #ifdef HAVE_X_WINDOWS
1184 /* Also, save clipboard to the clipboard manager. */
1185 x_clipboard_manager_save_frame (frame);
1186 #endif
1187
1188 safe_call2 (Qrun_hook_with_args, Qdelete_frame_functions, frame);
1189 }
1190
1191 /* The hook may sometimes (indirectly) cause the frame to be deleted. */
1192 if (! FRAME_LIVE_P (f))
1193 return Qnil;
1194
1195 /* At this point, we are committed to deleting the frame.
1196 There is no more chance for errors to prevent it. */
1197
1198 minibuffer_selected = EQ (minibuf_window, selected_window);
1199
1200 /* Don't let the frame remain selected. */
1201 if (f == sf)
1202 {
1203 Lisp_Object tail, frame1;
1204
1205 /* Look for another visible frame on the same terminal. */
1206 frame1 = next_frame (frame, Qvisible);
1207
1208 /* If there is none, find *some* other frame. */
1209 if (NILP (frame1) || EQ (frame1, frame))
1210 {
1211 FOR_EACH_FRAME (tail, frame1)
1212 {
1213 if (! EQ (frame, frame1) && FRAME_LIVE_P (XFRAME (frame1)))
1214 {
1215 /* Do not change a text terminal's top-frame. */
1216 struct frame *f1 = XFRAME (frame1);
1217 if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1))
1218 {
1219 Lisp_Object top_frame = FRAME_TTY (f1)->top_frame;
1220 if (!EQ (top_frame, frame))
1221 frame1 = top_frame;
1222 }
1223 break;
1224 }
1225 }
1226 }
1227 #ifdef NS_IMPL_COCOA
1228 else
1229 /* Under NS, there is no system mechanism for choosing a new
1230 window to get focus -- it is left to application code.
1231 So the portion of THIS application interfacing with NS
1232 needs to know about it. We call Fraise_frame, but the
1233 purpose is really to transfer focus. */
1234 Fraise_frame (frame1);
1235 #endif
1236
1237 do_switch_frame (frame1, 0, 1, Qnil);
1238 sf = SELECTED_FRAME ();
1239 }
1240
1241 /* Don't allow minibuf_window to remain on a deleted frame. */
1242 if (EQ (f->minibuffer_window, minibuf_window))
1243 {
1244 Fset_window_buffer (sf->minibuffer_window,
1245 XWINDOW (minibuf_window)->buffer, Qnil);
1246 minibuf_window = sf->minibuffer_window;
1247
1248 /* If the dying minibuffer window was selected,
1249 select the new one. */
1250 if (minibuffer_selected)
1251 Fselect_window (minibuf_window, Qnil);
1252 }
1253
1254 /* Don't let echo_area_window to remain on a deleted frame. */
1255 if (EQ (f->minibuffer_window, echo_area_window))
1256 echo_area_window = sf->minibuffer_window;
1257
1258 /* Clear any X selections for this frame. */
1259 #ifdef HAVE_X_WINDOWS
1260 if (FRAME_X_P (f))
1261 x_clear_frame_selections (f);
1262 #endif
1263
1264 /* Free glyphs.
1265 This function must be called before the window tree of the
1266 frame is deleted because windows contain dynamically allocated
1267 memory. */
1268 free_glyphs (f);
1269
1270 #ifdef HAVE_WINDOW_SYSTEM
1271 /* Give chance to each font driver to free a frame specific data. */
1272 font_update_drivers (f, Qnil);
1273 #endif
1274
1275 /* Mark all the windows that used to be on FRAME as deleted, and then
1276 remove the reference to them. */
1277 delete_all_child_windows (f->root_window);
1278 f->root_window = Qnil;
1279
1280 Vframe_list = Fdelq (frame, Vframe_list);
1281 FRAME_SET_VISIBLE (f, 0);
1282
1283 /* Allow the vector of menu bar contents to be freed in the next
1284 garbage collection. The frame object itself may not be garbage
1285 collected until much later, because recent_keys and other data
1286 structures can still refer to it. */
1287 f->menu_bar_vector = Qnil;
1288
1289 free_font_driver_list (f);
1290 xfree (f->namebuf);
1291 xfree (f->decode_mode_spec_buffer);
1292 xfree (FRAME_INSERT_COST (f));
1293 xfree (FRAME_DELETEN_COST (f));
1294 xfree (FRAME_INSERTN_COST (f));
1295 xfree (FRAME_DELETE_COST (f));
1296 xfree (FRAME_MESSAGE_BUF (f));
1297
1298 /* Since some events are handled at the interrupt level, we may get
1299 an event for f at any time; if we zero out the frame's terminal
1300 now, then we may trip up the event-handling code. Instead, we'll
1301 promise that the terminal of the frame must be valid until we
1302 have called the window-system-dependent frame destruction
1303 routine. */
1304
1305 if (FRAME_TERMINAL (f)->delete_frame_hook)
1306 (*FRAME_TERMINAL (f)->delete_frame_hook) (f);
1307
1308 {
1309 struct terminal *terminal = FRAME_TERMINAL (f);
1310 f->output_data.nothing = 0;
1311 f->terminal = 0; /* Now the frame is dead. */
1312
1313 /* If needed, delete the terminal that this frame was on.
1314 (This must be done after the frame is killed.) */
1315 terminal->reference_count--;
1316 #ifdef USE_GTK
1317 /* FIXME: Deleting the terminal crashes emacs because of a GTK
1318 bug.
1319 http://lists.gnu.org/archive/html/emacs-devel/2011-10/msg00363.html */
1320 if (terminal->reference_count == 0 && terminal->type == output_x_window)
1321 terminal->reference_count = 1;
1322 #endif /* USE_GTK */
1323 if (terminal->reference_count == 0)
1324 {
1325 Lisp_Object tmp;
1326 XSETTERMINAL (tmp, terminal);
1327
1328 kb = NULL;
1329 Fdelete_terminal (tmp, NILP (force) ? Qt : force);
1330 }
1331 else
1332 kb = terminal->kboard;
1333 }
1334
1335 /* If we've deleted the last_nonminibuf_frame, then try to find
1336 another one. */
1337 if (f == last_nonminibuf_frame)
1338 {
1339 Lisp_Object frames;
1340
1341 last_nonminibuf_frame = 0;
1342
1343 for (frames = Vframe_list;
1344 CONSP (frames);
1345 frames = XCDR (frames))
1346 {
1347 f = XFRAME (XCAR (frames));
1348 if (!FRAME_MINIBUF_ONLY_P (f))
1349 {
1350 last_nonminibuf_frame = f;
1351 break;
1352 }
1353 }
1354 }
1355
1356 /* If there's no other frame on the same kboard, get out of
1357 single-kboard state if we're in it for this kboard. */
1358 if (kb != NULL)
1359 {
1360 Lisp_Object frames;
1361 /* Some frame we found on the same kboard, or nil if there are none. */
1362 Lisp_Object frame_on_same_kboard;
1363
1364 frame_on_same_kboard = Qnil;
1365
1366 for (frames = Vframe_list;
1367 CONSP (frames);
1368 frames = XCDR (frames))
1369 {
1370 Lisp_Object this;
1371 struct frame *f1;
1372
1373 this = XCAR (frames);
1374 if (!FRAMEP (this))
1375 abort ();
1376 f1 = XFRAME (this);
1377
1378 if (kb == FRAME_KBOARD (f1))
1379 frame_on_same_kboard = this;
1380 }
1381
1382 if (NILP (frame_on_same_kboard))
1383 not_single_kboard_state (kb);
1384 }
1385
1386
1387 /* If we've deleted this keyboard's default_minibuffer_frame, try to
1388 find another one. Prefer minibuffer-only frames, but also notice
1389 frames with other windows. */
1390 if (kb != NULL && EQ (frame, KVAR (kb, Vdefault_minibuffer_frame)))
1391 {
1392 Lisp_Object frames;
1393
1394 /* The last frame we saw with a minibuffer, minibuffer-only or not. */
1395 Lisp_Object frame_with_minibuf;
1396 /* Some frame we found on the same kboard, or nil if there are none. */
1397 Lisp_Object frame_on_same_kboard;
1398
1399 frame_on_same_kboard = Qnil;
1400 frame_with_minibuf = Qnil;
1401
1402 for (frames = Vframe_list;
1403 CONSP (frames);
1404 frames = XCDR (frames))
1405 {
1406 Lisp_Object this;
1407 struct frame *f1;
1408
1409 this = XCAR (frames);
1410 if (!FRAMEP (this))
1411 abort ();
1412 f1 = XFRAME (this);
1413
1414 /* Consider only frames on the same kboard
1415 and only those with minibuffers. */
1416 if (kb == FRAME_KBOARD (f1)
1417 && FRAME_HAS_MINIBUF_P (f1))
1418 {
1419 frame_with_minibuf = this;
1420 if (FRAME_MINIBUF_ONLY_P (f1))
1421 break;
1422 }
1423
1424 if (kb == FRAME_KBOARD (f1))
1425 frame_on_same_kboard = this;
1426 }
1427
1428 if (!NILP (frame_on_same_kboard))
1429 {
1430 /* We know that there must be some frame with a minibuffer out
1431 there. If this were not true, all of the frames present
1432 would have to be minibufferless, which implies that at some
1433 point their minibuffer frames must have been deleted, but
1434 that is prohibited at the top; you can't delete surrogate
1435 minibuffer frames. */
1436 if (NILP (frame_with_minibuf))
1437 abort ();
1438
1439 KVAR (kb, Vdefault_minibuffer_frame) = frame_with_minibuf;
1440 }
1441 else
1442 /* No frames left on this kboard--say no minibuffer either. */
1443 KVAR (kb, Vdefault_minibuffer_frame) = Qnil;
1444 }
1445
1446 /* Cause frame titles to update--necessary if we now have just one frame. */
1447 if (!tooltip_frame)
1448 update_mode_lines = 1;
1449
1450 return Qnil;
1451 }
1452
1453 DEFUN ("delete-frame", Fdelete_frame, Sdelete_frame, 0, 2, "",
1454 doc: /* Delete FRAME, permanently eliminating it from use.
1455 FRAME defaults to the selected frame.
1456
1457 A frame may not be deleted if its minibuffer is used by other frames.
1458 Normally, you may not delete a frame if all other frames are invisible,
1459 but if the second optional argument FORCE is non-nil, you may do so.
1460
1461 This function runs `delete-frame-functions' before actually
1462 deleting the frame, unless the frame is a tooltip.
1463 The functions are run with one argument, the frame to be deleted. */)
1464 (Lisp_Object frame, Lisp_Object force)
1465 {
1466 return delete_frame (frame, !NILP (force) ? Qt : Qnil);
1467 }
1468
1469 \f
1470 /* Return mouse position in character cell units. */
1471
1472 DEFUN ("mouse-position", Fmouse_position, Smouse_position, 0, 0, 0,
1473 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1474 The position is given in character cells, where (0, 0) is the
1475 upper-left corner of the frame, X is the horizontal offset, and Y is
1476 the vertical offset.
1477 If Emacs is running on a mouseless terminal or hasn't been programmed
1478 to read the mouse position, it returns the selected frame for FRAME
1479 and nil for X and Y.
1480 If `mouse-position-function' is non-nil, `mouse-position' calls it,
1481 passing the normal return value to that function as an argument,
1482 and returns whatever that function returns. */)
1483 (void)
1484 {
1485 FRAME_PTR f;
1486 Lisp_Object lispy_dummy;
1487 enum scroll_bar_part party_dummy;
1488 Lisp_Object x, y, retval;
1489 int col, row;
1490 Time long_dummy;
1491 struct gcpro gcpro1;
1492
1493 f = SELECTED_FRAME ();
1494 x = y = Qnil;
1495
1496 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1497 /* It's okay for the hook to refrain from storing anything. */
1498 if (FRAME_TERMINAL (f)->mouse_position_hook)
1499 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1500 &lispy_dummy, &party_dummy,
1501 &x, &y,
1502 &long_dummy);
1503 if (! NILP (x))
1504 {
1505 col = XINT (x);
1506 row = XINT (y);
1507 pixel_to_glyph_coords (f, col, row, &col, &row, NULL, 1);
1508 XSETINT (x, col);
1509 XSETINT (y, row);
1510 }
1511 #endif
1512 XSETFRAME (lispy_dummy, f);
1513 retval = Fcons (lispy_dummy, Fcons (x, y));
1514 GCPRO1 (retval);
1515 if (!NILP (Vmouse_position_function))
1516 retval = call1 (Vmouse_position_function, retval);
1517 RETURN_UNGCPRO (retval);
1518 }
1519
1520 DEFUN ("mouse-pixel-position", Fmouse_pixel_position,
1521 Smouse_pixel_position, 0, 0, 0,
1522 doc: /* Return a list (FRAME X . Y) giving the current mouse frame and position.
1523 The position is given in pixel units, where (0, 0) is the
1524 upper-left corner of the frame, X is the horizontal offset, and Y is
1525 the vertical offset.
1526 If Emacs is running on a mouseless terminal or hasn't been programmed
1527 to read the mouse position, it returns the selected frame for FRAME
1528 and nil for X and Y. */)
1529 (void)
1530 {
1531 FRAME_PTR f;
1532 Lisp_Object lispy_dummy;
1533 enum scroll_bar_part party_dummy;
1534 Lisp_Object x, y;
1535 Time long_dummy;
1536
1537 f = SELECTED_FRAME ();
1538 x = y = Qnil;
1539
1540 #if defined (HAVE_MOUSE) || defined (HAVE_GPM)
1541 /* It's okay for the hook to refrain from storing anything. */
1542 if (FRAME_TERMINAL (f)->mouse_position_hook)
1543 (*FRAME_TERMINAL (f)->mouse_position_hook) (&f, -1,
1544 &lispy_dummy, &party_dummy,
1545 &x, &y,
1546 &long_dummy);
1547 #endif
1548 XSETFRAME (lispy_dummy, f);
1549 return Fcons (lispy_dummy, Fcons (x, y));
1550 }
1551
1552 DEFUN ("set-mouse-position", Fset_mouse_position, Sset_mouse_position, 3, 3, 0,
1553 doc: /* Move the mouse pointer to the center of character cell (X,Y) in FRAME.
1554 Coordinates are relative to the frame, not a window,
1555 so the coordinates of the top left character in the frame
1556 may be nonzero due to left-hand scroll bars or the menu bar.
1557
1558 The position is given in character cells, where (0, 0) is the
1559 upper-left corner of the frame, X is the horizontal offset, and Y is
1560 the vertical offset.
1561
1562 This function is a no-op for an X frame that is not visible.
1563 If you have just created a frame, you must wait for it to become visible
1564 before calling this function on it, like this.
1565 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1566 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1567 {
1568 CHECK_LIVE_FRAME (frame);
1569 CHECK_TYPE_RANGED_INTEGER (int, x);
1570 CHECK_TYPE_RANGED_INTEGER (int, y);
1571
1572 /* I think this should be done with a hook. */
1573 #ifdef HAVE_WINDOW_SYSTEM
1574 if (FRAME_WINDOW_P (XFRAME (frame)))
1575 /* Warping the mouse will cause enternotify and focus events. */
1576 x_set_mouse_position (XFRAME (frame), XINT (x), XINT (y));
1577 #else
1578 #if defined (MSDOS) && defined (HAVE_MOUSE)
1579 if (FRAME_MSDOS_P (XFRAME (frame)))
1580 {
1581 Fselect_frame (frame, Qnil);
1582 mouse_moveto (XINT (x), XINT (y));
1583 }
1584 #else
1585 #ifdef HAVE_GPM
1586 {
1587 Fselect_frame (frame, Qnil);
1588 term_mouse_moveto (XINT (x), XINT (y));
1589 }
1590 #endif
1591 #endif
1592 #endif
1593
1594 return Qnil;
1595 }
1596
1597 DEFUN ("set-mouse-pixel-position", Fset_mouse_pixel_position,
1598 Sset_mouse_pixel_position, 3, 3, 0,
1599 doc: /* Move the mouse pointer to pixel position (X,Y) in FRAME.
1600 The position is given in pixels, where (0, 0) is the upper-left corner
1601 of the frame, X is the horizontal offset, and Y is the vertical offset.
1602
1603 Note, this is a no-op for an X frame that is not visible.
1604 If you have just created a frame, you must wait for it to become visible
1605 before calling this function on it, like this.
1606 (while (not (frame-visible-p frame)) (sleep-for .5)) */)
1607 (Lisp_Object frame, Lisp_Object x, Lisp_Object y)
1608 {
1609 CHECK_LIVE_FRAME (frame);
1610 CHECK_TYPE_RANGED_INTEGER (int, x);
1611 CHECK_TYPE_RANGED_INTEGER (int, y);
1612
1613 /* I think this should be done with a hook. */
1614 #ifdef HAVE_WINDOW_SYSTEM
1615 if (FRAME_WINDOW_P (XFRAME (frame)))
1616 /* Warping the mouse will cause enternotify and focus events. */
1617 x_set_mouse_pixel_position (XFRAME (frame), XINT (x), XINT (y));
1618 #else
1619 #if defined (MSDOS) && defined (HAVE_MOUSE)
1620 if (FRAME_MSDOS_P (XFRAME (frame)))
1621 {
1622 Fselect_frame (frame, Qnil);
1623 mouse_moveto (XINT (x), XINT (y));
1624 }
1625 #else
1626 #ifdef HAVE_GPM
1627 {
1628 Fselect_frame (frame, Qnil);
1629 term_mouse_moveto (XINT (x), XINT (y));
1630 }
1631 #endif
1632 #endif
1633 #endif
1634
1635 return Qnil;
1636 }
1637 \f
1638 static void make_frame_visible_1 (Lisp_Object);
1639
1640 DEFUN ("make-frame-visible", Fmake_frame_visible, Smake_frame_visible,
1641 0, 1, "",
1642 doc: /* Make the frame FRAME visible (assuming it is an X window).
1643 If omitted, FRAME defaults to the currently selected frame. */)
1644 (Lisp_Object frame)
1645 {
1646 if (NILP (frame))
1647 frame = selected_frame;
1648
1649 CHECK_LIVE_FRAME (frame);
1650
1651 /* I think this should be done with a hook. */
1652 #ifdef HAVE_WINDOW_SYSTEM
1653 if (FRAME_WINDOW_P (XFRAME (frame)))
1654 {
1655 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1656 x_make_frame_visible (XFRAME (frame));
1657 }
1658 #endif
1659
1660 make_frame_visible_1 (XFRAME (frame)->root_window);
1661
1662 /* Make menu bar update for the Buffers and Frames menus. */
1663 windows_or_buffers_changed++;
1664
1665 return frame;
1666 }
1667
1668 /* Update the display_time slot of the buffers shown in WINDOW
1669 and all its descendants. */
1670
1671 static void
1672 make_frame_visible_1 (Lisp_Object window)
1673 {
1674 struct window *w;
1675
1676 for (;!NILP (window); window = w->next)
1677 {
1678 w = XWINDOW (window);
1679
1680 if (!NILP (w->buffer))
1681 BVAR (XBUFFER (w->buffer), display_time) = Fcurrent_time ();
1682
1683 if (!NILP (w->vchild))
1684 make_frame_visible_1 (w->vchild);
1685 if (!NILP (w->hchild))
1686 make_frame_visible_1 (w->hchild);
1687 }
1688 }
1689
1690 DEFUN ("make-frame-invisible", Fmake_frame_invisible, Smake_frame_invisible,
1691 0, 2, "",
1692 doc: /* Make the frame FRAME invisible.
1693 If omitted, FRAME defaults to the currently selected frame.
1694 On graphical displays, invisible frames are not updated and are
1695 usually not displayed at all, even in a window system's \"taskbar\".
1696
1697 Normally you may not make FRAME invisible if all other frames are invisible,
1698 but if the second optional argument FORCE is non-nil, you may do so.
1699
1700 This function has no effect on text terminal frames. Such frames are
1701 always considered visible, whether or not they are currently being
1702 displayed in the terminal. */)
1703 (Lisp_Object frame, Lisp_Object force)
1704 {
1705 if (NILP (frame))
1706 frame = selected_frame;
1707
1708 CHECK_LIVE_FRAME (frame);
1709
1710 if (NILP (force) && !other_visible_frames (XFRAME (frame)))
1711 error ("Attempt to make invisible the sole visible or iconified frame");
1712
1713 /* Don't allow minibuf_window to remain on a deleted frame. */
1714 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1715 {
1716 struct frame *sf = XFRAME (selected_frame);
1717 Fset_window_buffer (sf->minibuffer_window,
1718 XWINDOW (minibuf_window)->buffer, Qnil);
1719 minibuf_window = sf->minibuffer_window;
1720 }
1721
1722 /* I think this should be done with a hook. */
1723 #ifdef HAVE_WINDOW_SYSTEM
1724 if (FRAME_WINDOW_P (XFRAME (frame)))
1725 x_make_frame_invisible (XFRAME (frame));
1726 #endif
1727
1728 /* Make menu bar update for the Buffers and Frames menus. */
1729 windows_or_buffers_changed++;
1730
1731 return Qnil;
1732 }
1733
1734 DEFUN ("iconify-frame", Ficonify_frame, Siconify_frame,
1735 0, 1, "",
1736 doc: /* Make the frame FRAME into an icon.
1737 If omitted, FRAME defaults to the currently selected frame. */)
1738 (Lisp_Object frame)
1739 {
1740 if (NILP (frame))
1741 frame = selected_frame;
1742
1743 CHECK_LIVE_FRAME (frame);
1744
1745 #if 0 /* This isn't logically necessary, and it can do GC. */
1746 /* Don't let the frame remain selected. */
1747 if (EQ (frame, selected_frame))
1748 Fhandle_switch_frame (next_frame (frame, Qt));
1749 #endif
1750
1751 /* Don't allow minibuf_window to remain on a deleted frame. */
1752 if (EQ (XFRAME (frame)->minibuffer_window, minibuf_window))
1753 {
1754 struct frame *sf = XFRAME (selected_frame);
1755 Fset_window_buffer (sf->minibuffer_window,
1756 XWINDOW (minibuf_window)->buffer, Qnil);
1757 minibuf_window = sf->minibuffer_window;
1758 }
1759
1760 /* I think this should be done with a hook. */
1761 #ifdef HAVE_WINDOW_SYSTEM
1762 if (FRAME_WINDOW_P (XFRAME (frame)))
1763 x_iconify_frame (XFRAME (frame));
1764 #endif
1765
1766 /* Make menu bar update for the Buffers and Frames menus. */
1767 windows_or_buffers_changed++;
1768
1769 return Qnil;
1770 }
1771
1772 DEFUN ("frame-visible-p", Fframe_visible_p, Sframe_visible_p,
1773 1, 1, 0,
1774 doc: /* Return t if FRAME is \"visible\" (actually in use for display).
1775 Return the symbol `icon' if FRAME is iconified or \"minimized\".
1776 Return nil if FRAME was made invisible, via `make-frame-invisible'.
1777 On graphical displays, invisible frames are not updated and are
1778 usually not displayed at all, even in a window system's \"taskbar\".
1779
1780 If FRAME is a text terminal frame, this always returns t.
1781 Such frames are always considered visible, whether or not they are
1782 currently being displayed on the terminal. */)
1783 (Lisp_Object frame)
1784 {
1785 CHECK_LIVE_FRAME (frame);
1786
1787 FRAME_SAMPLE_VISIBILITY (XFRAME (frame));
1788
1789 if (FRAME_VISIBLE_P (XFRAME (frame)))
1790 return Qt;
1791 if (FRAME_ICONIFIED_P (XFRAME (frame)))
1792 return Qicon;
1793 return Qnil;
1794 }
1795
1796 DEFUN ("visible-frame-list", Fvisible_frame_list, Svisible_frame_list,
1797 0, 0, 0,
1798 doc: /* Return a list of all frames now \"visible\" (being updated). */)
1799 (void)
1800 {
1801 Lisp_Object tail, frame;
1802 struct frame *f;
1803 Lisp_Object value;
1804
1805 value = Qnil;
1806 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1807 {
1808 frame = XCAR (tail);
1809 if (!FRAMEP (frame))
1810 continue;
1811 f = XFRAME (frame);
1812 if (FRAME_VISIBLE_P (f))
1813 value = Fcons (frame, value);
1814 }
1815 return value;
1816 }
1817
1818
1819 DEFUN ("raise-frame", Fraise_frame, Sraise_frame, 0, 1, "",
1820 doc: /* Bring FRAME to the front, so it occludes any frames it overlaps.
1821 If FRAME is invisible or iconified, make it visible.
1822 If you don't specify a frame, the selected frame is used.
1823 If Emacs is displaying on an ordinary terminal or some other device which
1824 doesn't support multiple overlapping frames, this function selects FRAME. */)
1825 (Lisp_Object frame)
1826 {
1827 struct frame *f;
1828 if (NILP (frame))
1829 frame = selected_frame;
1830
1831 CHECK_LIVE_FRAME (frame);
1832
1833 f = XFRAME (frame);
1834
1835 if (FRAME_TERMCAP_P (f))
1836 /* On a text terminal select FRAME. */
1837 Fselect_frame (frame, Qnil);
1838 else
1839 /* Do like the documentation says. */
1840 Fmake_frame_visible (frame);
1841
1842 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1843 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
1844
1845 return Qnil;
1846 }
1847
1848 /* Should we have a corresponding function called Flower_Power? */
1849 DEFUN ("lower-frame", Flower_frame, Slower_frame, 0, 1, "",
1850 doc: /* Send FRAME to the back, so it is occluded by any frames that overlap it.
1851 If you don't specify a frame, the selected frame is used.
1852 If Emacs is displaying on an ordinary terminal or some other device which
1853 doesn't support multiple overlapping frames, this function does nothing. */)
1854 (Lisp_Object frame)
1855 {
1856 struct frame *f;
1857
1858 if (NILP (frame))
1859 frame = selected_frame;
1860
1861 CHECK_LIVE_FRAME (frame);
1862
1863 f = XFRAME (frame);
1864
1865 if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
1866 (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
1867
1868 return Qnil;
1869 }
1870
1871 \f
1872 DEFUN ("redirect-frame-focus", Fredirect_frame_focus, Sredirect_frame_focus,
1873 1, 2, 0,
1874 doc: /* Arrange for keystrokes typed at FRAME to be sent to FOCUS-FRAME.
1875 In other words, switch-frame events caused by events in FRAME will
1876 request a switch to FOCUS-FRAME, and `last-event-frame' will be
1877 FOCUS-FRAME after reading an event typed at FRAME.
1878
1879 If FOCUS-FRAME is omitted or nil, any existing redirection is
1880 canceled, and the frame again receives its own keystrokes.
1881
1882 Focus redirection is useful for temporarily redirecting keystrokes to
1883 a surrogate minibuffer frame when a frame doesn't have its own
1884 minibuffer window.
1885
1886 A frame's focus redirection can be changed by `select-frame'. If frame
1887 FOO is selected, and then a different frame BAR is selected, any
1888 frames redirecting their focus to FOO are shifted to redirect their
1889 focus to BAR. This allows focus redirection to work properly when the
1890 user switches from one frame to another using `select-window'.
1891
1892 This means that a frame whose focus is redirected to itself is treated
1893 differently from a frame whose focus is redirected to nil; the former
1894 is affected by `select-frame', while the latter is not.
1895
1896 The redirection lasts until `redirect-frame-focus' is called to change it. */)
1897 (Lisp_Object frame, Lisp_Object focus_frame)
1898 {
1899 struct frame *f;
1900
1901 /* Note that we don't check for a live frame here. It's reasonable
1902 to redirect the focus of a frame you're about to delete, if you
1903 know what other frame should receive those keystrokes. */
1904 CHECK_FRAME (frame);
1905
1906 if (! NILP (focus_frame))
1907 CHECK_LIVE_FRAME (focus_frame);
1908
1909 f = XFRAME (frame);
1910
1911 f->focus_frame = focus_frame;
1912
1913 if (FRAME_TERMINAL (f)->frame_rehighlight_hook)
1914 (*FRAME_TERMINAL (f)->frame_rehighlight_hook) (f);
1915
1916 return Qnil;
1917 }
1918
1919
1920 DEFUN ("frame-focus", Fframe_focus, Sframe_focus, 1, 1, 0,
1921 doc: /* Return the frame to which FRAME's keystrokes are currently being sent.
1922 This returns nil if FRAME's focus is not redirected.
1923 See `redirect-frame-focus'. */)
1924 (Lisp_Object frame)
1925 {
1926 CHECK_LIVE_FRAME (frame);
1927
1928 return FRAME_FOCUS_FRAME (XFRAME (frame));
1929 }
1930
1931
1932 \f
1933 /* Return the value of frame parameter PROP in frame FRAME. */
1934
1935 #if !HAVE_NS
1936 static
1937 #endif
1938 Lisp_Object
1939 get_frame_param (register struct frame *frame, Lisp_Object prop)
1940 {
1941 register Lisp_Object tem;
1942
1943 tem = Fassq (prop, frame->param_alist);
1944 if (EQ (tem, Qnil))
1945 return tem;
1946 return Fcdr (tem);
1947 }
1948
1949 /* Return the buffer-predicate of the selected frame. */
1950
1951 Lisp_Object
1952 frame_buffer_predicate (Lisp_Object frame)
1953 {
1954 return XFRAME (frame)->buffer_predicate;
1955 }
1956
1957 /* Return the buffer-list of the selected frame. */
1958
1959 static Lisp_Object
1960 frame_buffer_list (Lisp_Object frame)
1961 {
1962 return XFRAME (frame)->buffer_list;
1963 }
1964
1965 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1966
1967 void
1968 frames_discard_buffer (Lisp_Object buffer)
1969 {
1970 Lisp_Object frame, tail;
1971
1972 FOR_EACH_FRAME (tail, frame)
1973 {
1974 XFRAME (frame)->buffer_list
1975 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1976 XFRAME (frame)->buried_buffer_list
1977 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
1978 }
1979 }
1980
1981 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1982 If the alist already has an element for PROP, we change it. */
1983
1984 void
1985 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1986 {
1987 register Lisp_Object tem;
1988
1989 tem = Fassq (prop, *alistptr);
1990 if (EQ (tem, Qnil))
1991 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1992 else
1993 Fsetcdr (tem, val);
1994 }
1995
1996 static int
1997 frame_name_fnn_p (char *str, ptrdiff_t len)
1998 {
1999 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2000 {
2001 char *p = str + 2;
2002 while ('0' <= *p && *p <= '9')
2003 p++;
2004 if (p == str + len)
2005 return 1;
2006 }
2007 return 0;
2008 }
2009
2010 /* Set the name of the terminal frame. Also used by MSDOS frames.
2011 Modeled after x_set_name which is used for WINDOW frames. */
2012
2013 static void
2014 set_term_frame_name (struct frame *f, Lisp_Object name)
2015 {
2016 f->explicit_name = ! NILP (name);
2017
2018 /* If NAME is nil, set the name to F<num>. */
2019 if (NILP (name))
2020 {
2021 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2022
2023 /* Check for no change needed in this very common case
2024 before we do any consing. */
2025 if (frame_name_fnn_p (SSDATA (f->name),
2026 SBYTES (f->name)))
2027 return;
2028
2029 tty_frame_count++;
2030 sprintf (namebuf, "F%"pMd, tty_frame_count);
2031 name = build_string (namebuf);
2032 }
2033 else
2034 {
2035 CHECK_STRING (name);
2036
2037 /* Don't change the name if it's already NAME. */
2038 if (! NILP (Fstring_equal (name, f->name)))
2039 return;
2040
2041 /* Don't allow the user to set the frame name to F<num>, so it
2042 doesn't clash with the names we generate for terminal frames. */
2043 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2044 error ("Frame names of the form F<num> are usurped by Emacs");
2045 }
2046
2047 f->name = name;
2048 update_mode_lines = 1;
2049 }
2050
2051 void
2052 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2053 {
2054 register Lisp_Object old_alist_elt;
2055
2056 /* The buffer-list parameters are stored in a special place and not
2057 in the alist. All buffers must be live. */
2058 if (EQ (prop, Qbuffer_list))
2059 {
2060 Lisp_Object list = Qnil;
2061 for (; CONSP (val); val = XCDR (val))
2062 if (!NILP (Fbuffer_live_p (XCAR (val))))
2063 list = Fcons (XCAR (val), list);
2064 f->buffer_list = Fnreverse (list);
2065 return;
2066 }
2067 if (EQ (prop, Qburied_buffer_list))
2068 {
2069 Lisp_Object list = Qnil;
2070 for (; CONSP (val); val = XCDR (val))
2071 if (!NILP (Fbuffer_live_p (XCAR (val))))
2072 list = Fcons (XCAR (val), list);
2073 f->buried_buffer_list = Fnreverse (list);
2074 return;
2075 }
2076
2077 /* If PROP is a symbol which is supposed to have frame-local values,
2078 and it is set up based on this frame, switch to the global
2079 binding. That way, we can create or alter the frame-local binding
2080 without messing up the symbol's status. */
2081 if (SYMBOLP (prop))
2082 {
2083 struct Lisp_Symbol *sym = XSYMBOL (prop);
2084 start:
2085 switch (sym->redirect)
2086 {
2087 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2088 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2089 case SYMBOL_LOCALIZED:
2090 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2091 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2092 swap_in_global_binding (sym);
2093 break;
2094 }
2095 default: abort ();
2096 }
2097 }
2098
2099 /* The tty color needed to be set before the frame's parameter
2100 alist was updated with the new value. This is not true any more,
2101 but we still do this test early on. */
2102 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2103 && f == FRAME_TTY (f)->previous_frame)
2104 /* Force redisplay of this tty. */
2105 FRAME_TTY (f)->previous_frame = NULL;
2106
2107 /* Update the frame parameter alist. */
2108 old_alist_elt = Fassq (prop, f->param_alist);
2109 if (EQ (old_alist_elt, Qnil))
2110 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2111 else
2112 Fsetcdr (old_alist_elt, val);
2113
2114 /* Update some other special parameters in their special places
2115 in addition to the alist. */
2116
2117 if (EQ (prop, Qbuffer_predicate))
2118 f->buffer_predicate = val;
2119
2120 if (! FRAME_WINDOW_P (f))
2121 {
2122 if (EQ (prop, Qmenu_bar_lines))
2123 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2124 else if (EQ (prop, Qname))
2125 set_term_frame_name (f, val);
2126 }
2127
2128 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2129 {
2130 if (! MINI_WINDOW_P (XWINDOW (val)))
2131 error ("Surrogate minibuffer windows must be minibuffer windows");
2132
2133 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2134 && !EQ (val, f->minibuffer_window))
2135 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2136
2137 /* Install the chosen minibuffer window, with proper buffer. */
2138 f->minibuffer_window = val;
2139 }
2140 }
2141
2142 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2143 doc: /* Return the parameters-alist of frame FRAME.
2144 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2145 The meaningful PARMs depend on the kind of frame.
2146 If FRAME is omitted, return information on the currently selected frame. */)
2147 (Lisp_Object frame)
2148 {
2149 Lisp_Object alist;
2150 FRAME_PTR f;
2151 int height, width;
2152 struct gcpro gcpro1;
2153
2154 if (NILP (frame))
2155 frame = selected_frame;
2156
2157 CHECK_FRAME (frame);
2158 f = XFRAME (frame);
2159
2160 if (!FRAME_LIVE_P (f))
2161 return Qnil;
2162
2163 alist = Fcopy_alist (f->param_alist);
2164 GCPRO1 (alist);
2165
2166 if (!FRAME_WINDOW_P (f))
2167 {
2168 int fg = FRAME_FOREGROUND_PIXEL (f);
2169 int bg = FRAME_BACKGROUND_PIXEL (f);
2170 Lisp_Object elt;
2171
2172 /* If the frame's parameter alist says the colors are
2173 unspecified and reversed, take the frame's background pixel
2174 for foreground and vice versa. */
2175 elt = Fassq (Qforeground_color, alist);
2176 if (CONSP (elt) && STRINGP (XCDR (elt)))
2177 {
2178 if (strncmp (SSDATA (XCDR (elt)),
2179 unspecified_bg,
2180 SCHARS (XCDR (elt))) == 0)
2181 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2182 else if (strncmp (SSDATA (XCDR (elt)),
2183 unspecified_fg,
2184 SCHARS (XCDR (elt))) == 0)
2185 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2186 }
2187 else
2188 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2189 elt = Fassq (Qbackground_color, alist);
2190 if (CONSP (elt) && STRINGP (XCDR (elt)))
2191 {
2192 if (strncmp (SSDATA (XCDR (elt)),
2193 unspecified_fg,
2194 SCHARS (XCDR (elt))) == 0)
2195 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2196 else if (strncmp (SSDATA (XCDR (elt)),
2197 unspecified_bg,
2198 SCHARS (XCDR (elt))) == 0)
2199 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2200 }
2201 else
2202 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2203 store_in_alist (&alist, intern ("font"),
2204 build_string (FRAME_MSDOS_P (f)
2205 ? "ms-dos"
2206 : FRAME_W32_P (f) ? "w32term"
2207 :"tty"));
2208 }
2209 store_in_alist (&alist, Qname, f->name);
2210 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2211 store_in_alist (&alist, Qheight, make_number (height));
2212 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2213 store_in_alist (&alist, Qwidth, make_number (width));
2214 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2215 store_in_alist (&alist, Qminibuffer,
2216 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2217 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2218 : FRAME_MINIBUF_WINDOW (f)));
2219 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2220 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2221 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2222
2223 /* I think this should be done with a hook. */
2224 #ifdef HAVE_WINDOW_SYSTEM
2225 if (FRAME_WINDOW_P (f))
2226 x_report_frame_params (f, &alist);
2227 else
2228 #endif
2229 {
2230 /* This ought to be correct in f->param_alist for an X frame. */
2231 Lisp_Object lines;
2232 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2233 store_in_alist (&alist, Qmenu_bar_lines, lines);
2234 }
2235
2236 UNGCPRO;
2237 return alist;
2238 }
2239
2240
2241 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2242 doc: /* Return FRAME's value for parameter PARAMETER.
2243 If FRAME is nil, describe the currently selected frame. */)
2244 (Lisp_Object frame, Lisp_Object parameter)
2245 {
2246 struct frame *f;
2247 Lisp_Object value;
2248
2249 if (NILP (frame))
2250 frame = selected_frame;
2251 else
2252 CHECK_FRAME (frame);
2253 CHECK_SYMBOL (parameter);
2254
2255 f = XFRAME (frame);
2256 value = Qnil;
2257
2258 if (FRAME_LIVE_P (f))
2259 {
2260 /* Avoid consing in frequent cases. */
2261 if (EQ (parameter, Qname))
2262 value = f->name;
2263 #ifdef HAVE_X_WINDOWS
2264 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2265 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2266 #endif /* HAVE_X_WINDOWS */
2267 else if (EQ (parameter, Qbackground_color)
2268 || EQ (parameter, Qforeground_color))
2269 {
2270 value = Fassq (parameter, f->param_alist);
2271 if (CONSP (value))
2272 {
2273 value = XCDR (value);
2274 /* Fframe_parameters puts the actual fg/bg color names,
2275 even if f->param_alist says otherwise. This is
2276 important when param_alist's notion of colors is
2277 "unspecified". We need to do the same here. */
2278 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2279 {
2280 const char *color_name;
2281 ptrdiff_t csz;
2282
2283 if (EQ (parameter, Qbackground_color))
2284 {
2285 color_name = SSDATA (value);
2286 csz = SCHARS (value);
2287 if (strncmp (color_name, unspecified_bg, csz) == 0)
2288 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2289 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2290 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2291 }
2292 else if (EQ (parameter, Qforeground_color))
2293 {
2294 color_name = SSDATA (value);
2295 csz = SCHARS (value);
2296 if (strncmp (color_name, unspecified_fg, csz) == 0)
2297 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2298 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2299 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2300 }
2301 }
2302 }
2303 else
2304 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2305 }
2306 else if (EQ (parameter, Qdisplay_type)
2307 || EQ (parameter, Qbackground_mode))
2308 value = Fcdr (Fassq (parameter, f->param_alist));
2309 else
2310 /* FIXME: Avoid this code path at all (as well as code duplication)
2311 by sharing more code with Fframe_parameters. */
2312 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2313 }
2314
2315 return value;
2316 }
2317
2318
2319 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2320 Smodify_frame_parameters, 2, 2, 0,
2321 doc: /* Modify the parameters of frame FRAME according to ALIST.
2322 If FRAME is nil, it defaults to the selected frame.
2323 ALIST is an alist of parameters to change and their new values.
2324 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2325 The meaningful PARMs depend on the kind of frame.
2326 Undefined PARMs are ignored, but stored in the frame's parameter list
2327 so that `frame-parameters' will return them.
2328
2329 The value of frame parameter FOO can also be accessed
2330 as a frame-local binding for the variable FOO, if you have
2331 enabled such bindings for that variable with `make-variable-frame-local'.
2332 Note that this functionality is obsolete as of Emacs 22.2, and its
2333 use is not recommended. Explicitly check for a frame-parameter instead. */)
2334 (Lisp_Object frame, Lisp_Object alist)
2335 {
2336 FRAME_PTR f;
2337 register Lisp_Object tail, prop, val;
2338
2339 if (EQ (frame, Qnil))
2340 frame = selected_frame;
2341 CHECK_LIVE_FRAME (frame);
2342 f = XFRAME (frame);
2343
2344 /* I think this should be done with a hook. */
2345 #ifdef HAVE_WINDOW_SYSTEM
2346 if (FRAME_WINDOW_P (f))
2347 x_set_frame_parameters (f, alist);
2348 else
2349 #endif
2350 #ifdef MSDOS
2351 if (FRAME_MSDOS_P (f))
2352 IT_set_frame_parameters (f, alist);
2353 else
2354 #endif
2355
2356 {
2357 EMACS_INT length = XFASTINT (Flength (alist));
2358 ptrdiff_t i;
2359 Lisp_Object *parms;
2360 Lisp_Object *values;
2361 USE_SAFE_ALLOCA;
2362 SAFE_ALLOCA_LISP (parms, 2 * length);
2363 values = parms + length;
2364
2365 /* Extract parm names and values into those vectors. */
2366
2367 i = 0;
2368 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2369 {
2370 Lisp_Object elt;
2371
2372 elt = XCAR (tail);
2373 parms[i] = Fcar (elt);
2374 values[i] = Fcdr (elt);
2375 i++;
2376 }
2377
2378 /* Now process them in reverse of specified order. */
2379 while (--i >= 0)
2380 {
2381 prop = parms[i];
2382 val = values[i];
2383 store_frame_param (f, prop, val);
2384
2385 if (EQ (prop, Qforeground_color)
2386 || EQ (prop, Qbackground_color))
2387 update_face_from_frame_parameter (f, prop, val);
2388 }
2389
2390 SAFE_FREE ();
2391 }
2392 return Qnil;
2393 }
2394 \f
2395 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2396 0, 1, 0,
2397 doc: /* Height in pixels of a line in the font in frame FRAME.
2398 If FRAME is omitted, the selected frame is used.
2399 For a terminal frame, the value is always 1. */)
2400 (Lisp_Object frame)
2401 {
2402 struct frame *f;
2403
2404 if (NILP (frame))
2405 frame = selected_frame;
2406 CHECK_FRAME (frame);
2407 f = XFRAME (frame);
2408
2409 #ifdef HAVE_WINDOW_SYSTEM
2410 if (FRAME_WINDOW_P (f))
2411 return make_number (x_char_height (f));
2412 else
2413 #endif
2414 return make_number (1);
2415 }
2416
2417
2418 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2419 0, 1, 0,
2420 doc: /* Width in pixels of characters in the font in frame FRAME.
2421 If FRAME is omitted, the selected frame is used.
2422 On a graphical screen, the width is the standard width of the default font.
2423 For a terminal screen, the value is always 1. */)
2424 (Lisp_Object frame)
2425 {
2426 struct frame *f;
2427
2428 if (NILP (frame))
2429 frame = selected_frame;
2430 CHECK_FRAME (frame);
2431 f = XFRAME (frame);
2432
2433 #ifdef HAVE_WINDOW_SYSTEM
2434 if (FRAME_WINDOW_P (f))
2435 return make_number (x_char_width (f));
2436 else
2437 #endif
2438 return make_number (1);
2439 }
2440
2441 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2442 Sframe_pixel_height, 0, 1, 0,
2443 doc: /* Return a FRAME's height in pixels.
2444 If FRAME is omitted, the selected frame is used. The exact value
2445 of the result depends on the window-system and toolkit in use:
2446
2447 In the Gtk+ version of Emacs, it includes only any window (including
2448 the minibuffer or echo area), mode line, and header line. It does not
2449 include the tool bar or menu bar.
2450
2451 With the Motif or Lucid toolkits, it also includes the tool bar (but
2452 not the menu bar).
2453
2454 In a graphical version with no toolkit, it includes both the tool bar
2455 and menu bar.
2456
2457 For a text terminal, it includes the menu bar. In this case, the
2458 result is really in characters rather than pixels (i.e., is identical
2459 to `frame-height'). */)
2460 (Lisp_Object frame)
2461 {
2462 struct frame *f;
2463
2464 if (NILP (frame))
2465 frame = selected_frame;
2466 CHECK_FRAME (frame);
2467 f = XFRAME (frame);
2468
2469 #ifdef HAVE_WINDOW_SYSTEM
2470 if (FRAME_WINDOW_P (f))
2471 return make_number (x_pixel_height (f));
2472 else
2473 #endif
2474 return make_number (FRAME_LINES (f));
2475 }
2476
2477 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2478 Sframe_pixel_width, 0, 1, 0,
2479 doc: /* Return FRAME's width in pixels.
2480 For a terminal frame, the result really gives the width in characters.
2481 If FRAME is omitted, the selected frame is used. */)
2482 (Lisp_Object frame)
2483 {
2484 struct frame *f;
2485
2486 if (NILP (frame))
2487 frame = selected_frame;
2488 CHECK_FRAME (frame);
2489 f = XFRAME (frame);
2490
2491 #ifdef HAVE_WINDOW_SYSTEM
2492 if (FRAME_WINDOW_P (f))
2493 return make_number (x_pixel_width (f));
2494 else
2495 #endif
2496 return make_number (FRAME_COLS (f));
2497 }
2498
2499 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2500 Stool_bar_pixel_width, 0, 1, 0,
2501 doc: /* Return width in pixels of FRAME's tool bar.
2502 The result is greater than zero only when the tool bar is on the left
2503 or right side of FRAME. If FRAME is omitted, the selected frame is
2504 used. */)
2505 (Lisp_Object frame)
2506 {
2507 struct frame *f;
2508
2509 if (NILP (frame))
2510 frame = selected_frame;
2511 CHECK_FRAME (frame);
2512 f = XFRAME (frame);
2513
2514 #ifdef FRAME_TOOLBAR_WIDTH
2515 if (FRAME_WINDOW_P (f))
2516 return make_number (FRAME_TOOLBAR_WIDTH (f));
2517 #endif
2518 return make_number (0);
2519 }
2520 \f
2521 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2522 doc: /* Specify that the frame FRAME has LINES lines.
2523 Optional third arg non-nil means that redisplay should use LINES lines
2524 but that the idea of the actual height of the frame should not be changed. */)
2525 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2526 {
2527 register struct frame *f;
2528
2529 CHECK_TYPE_RANGED_INTEGER (int, lines);
2530 if (NILP (frame))
2531 frame = selected_frame;
2532 CHECK_LIVE_FRAME (frame);
2533 f = XFRAME (frame);
2534
2535 /* I think this should be done with a hook. */
2536 #ifdef HAVE_WINDOW_SYSTEM
2537 if (FRAME_WINDOW_P (f))
2538 {
2539 if (XINT (lines) != FRAME_LINES (f))
2540 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2541 do_pending_window_change (0);
2542 }
2543 else
2544 #endif
2545 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2546 return Qnil;
2547 }
2548
2549 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2550 doc: /* Specify that the frame FRAME has COLS columns.
2551 Optional third arg non-nil means that redisplay should use COLS columns
2552 but that the idea of the actual width of the frame should not be changed. */)
2553 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2554 {
2555 register struct frame *f;
2556 CHECK_TYPE_RANGED_INTEGER (int, cols);
2557 if (NILP (frame))
2558 frame = selected_frame;
2559 CHECK_LIVE_FRAME (frame);
2560 f = XFRAME (frame);
2561
2562 /* I think this should be done with a hook. */
2563 #ifdef HAVE_WINDOW_SYSTEM
2564 if (FRAME_WINDOW_P (f))
2565 {
2566 if (XINT (cols) != FRAME_COLS (f))
2567 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2568 do_pending_window_change (0);
2569 }
2570 else
2571 #endif
2572 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2573 return Qnil;
2574 }
2575
2576 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2577 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2578 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2579 {
2580 register struct frame *f;
2581
2582 CHECK_LIVE_FRAME (frame);
2583 CHECK_TYPE_RANGED_INTEGER (int, cols);
2584 CHECK_TYPE_RANGED_INTEGER (int, rows);
2585 f = XFRAME (frame);
2586
2587 /* I think this should be done with a hook. */
2588 #ifdef HAVE_WINDOW_SYSTEM
2589 if (FRAME_WINDOW_P (f))
2590 {
2591 if (XINT (rows) != FRAME_LINES (f)
2592 || XINT (cols) != FRAME_COLS (f)
2593 || f->new_text_lines || f->new_text_cols)
2594 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2595 do_pending_window_change (0);
2596 }
2597 else
2598 #endif
2599 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2600
2601 return Qnil;
2602 }
2603
2604 DEFUN ("set-frame-position", Fset_frame_position,
2605 Sset_frame_position, 3, 3, 0,
2606 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2607 This is actually the position of the upper left corner of the frame.
2608 Negative values for XOFFSET or YOFFSET are interpreted relative to
2609 the rightmost or bottommost possible position (that stays within the screen). */)
2610 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2611 {
2612 register struct frame *f;
2613
2614 CHECK_LIVE_FRAME (frame);
2615 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2616 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2617 f = XFRAME (frame);
2618
2619 /* I think this should be done with a hook. */
2620 #ifdef HAVE_WINDOW_SYSTEM
2621 if (FRAME_WINDOW_P (f))
2622 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2623 #endif
2624
2625 return Qt;
2626 }
2627
2628 \f
2629 /***********************************************************************
2630 Frame Parameters
2631 ***********************************************************************/
2632
2633 /* Connect the frame-parameter names for X frames
2634 to the ways of passing the parameter values to the window system.
2635
2636 The name of a parameter, as a Lisp symbol,
2637 has an `x-frame-parameter' property which is an integer in Lisp
2638 that is an index in this table. */
2639
2640 struct frame_parm_table {
2641 const char *name;
2642 Lisp_Object *variable;
2643 };
2644
2645 static const struct frame_parm_table frame_parms[] =
2646 {
2647 {"auto-raise", &Qauto_raise},
2648 {"auto-lower", &Qauto_lower},
2649 {"background-color", 0},
2650 {"border-color", &Qborder_color},
2651 {"border-width", &Qborder_width},
2652 {"cursor-color", &Qcursor_color},
2653 {"cursor-type", &Qcursor_type},
2654 {"font", 0},
2655 {"foreground-color", 0},
2656 {"icon-name", &Qicon_name},
2657 {"icon-type", &Qicon_type},
2658 {"internal-border-width", &Qinternal_border_width},
2659 {"menu-bar-lines", &Qmenu_bar_lines},
2660 {"mouse-color", &Qmouse_color},
2661 {"name", &Qname},
2662 {"scroll-bar-width", &Qscroll_bar_width},
2663 {"title", &Qtitle},
2664 {"unsplittable", &Qunsplittable},
2665 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2666 {"visibility", &Qvisibility},
2667 {"tool-bar-lines", &Qtool_bar_lines},
2668 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2669 {"scroll-bar-background", &Qscroll_bar_background},
2670 {"screen-gamma", &Qscreen_gamma},
2671 {"line-spacing", &Qline_spacing},
2672 {"left-fringe", &Qleft_fringe},
2673 {"right-fringe", &Qright_fringe},
2674 {"wait-for-wm", &Qwait_for_wm},
2675 {"fullscreen", &Qfullscreen},
2676 {"font-backend", &Qfont_backend},
2677 {"alpha", &Qalpha},
2678 {"sticky", &Qsticky},
2679 {"tool-bar-position", &Qtool_bar_position},
2680 };
2681
2682 #ifdef WINDOWSNT
2683
2684 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2685 wanted positions of the WM window (not Emacs window).
2686 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2687 window (FRAME_X_WINDOW).
2688 */
2689
2690 void
2691 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2692 {
2693 int newwidth = FRAME_COLS (f);
2694 int newheight = FRAME_LINES (f);
2695 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2696
2697 *top_pos = f->top_pos;
2698 *left_pos = f->left_pos;
2699
2700 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2701 {
2702 int ph;
2703
2704 ph = x_display_pixel_height (dpyinfo);
2705 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2706 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2707 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2708 *top_pos = 0;
2709 }
2710
2711 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2712 {
2713 int pw;
2714
2715 pw = x_display_pixel_width (dpyinfo);
2716 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2717 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2718 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2719 *left_pos = 0;
2720 }
2721
2722 *width = newwidth;
2723 *height = newheight;
2724 }
2725
2726 #endif /* WINDOWSNT */
2727
2728 #ifdef HAVE_WINDOW_SYSTEM
2729
2730 /* Change the parameters of frame F as specified by ALIST.
2731 If a parameter is not specially recognized, do nothing special;
2732 otherwise call the `x_set_...' function for that parameter.
2733 Except for certain geometry properties, always call store_frame_param
2734 to store the new value in the parameter alist. */
2735
2736 void
2737 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2738 {
2739 Lisp_Object tail;
2740
2741 /* If both of these parameters are present, it's more efficient to
2742 set them both at once. So we wait until we've looked at the
2743 entire list before we set them. */
2744 int width, height;
2745
2746 /* Same here. */
2747 Lisp_Object left, top;
2748
2749 /* Same with these. */
2750 Lisp_Object icon_left, icon_top;
2751
2752 /* Record in these vectors all the parms specified. */
2753 Lisp_Object *parms;
2754 Lisp_Object *values;
2755 ptrdiff_t i, p;
2756 int left_no_change = 0, top_no_change = 0;
2757 int icon_left_no_change = 0, icon_top_no_change = 0;
2758 int size_changed = 0;
2759 struct gcpro gcpro1, gcpro2;
2760
2761 i = 0;
2762 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2763 i++;
2764
2765 parms = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2766 values = (Lisp_Object *) alloca (i * sizeof (Lisp_Object));
2767
2768 /* Extract parm names and values into those vectors. */
2769
2770 i = 0;
2771 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2772 {
2773 Lisp_Object elt;
2774
2775 elt = XCAR (tail);
2776 parms[i] = Fcar (elt);
2777 values[i] = Fcdr (elt);
2778 i++;
2779 }
2780 /* TAIL and ALIST are not used again below here. */
2781 alist = tail = Qnil;
2782
2783 GCPRO2 (*parms, *values);
2784 gcpro1.nvars = i;
2785 gcpro2.nvars = i;
2786
2787 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2788 because their values appear in VALUES and strings are not valid. */
2789 top = left = Qunbound;
2790 icon_left = icon_top = Qunbound;
2791
2792 /* Provide default values for HEIGHT and WIDTH. */
2793 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2794 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2795
2796 /* Process foreground_color and background_color before anything else.
2797 They are independent of other properties, but other properties (e.g.,
2798 cursor_color) are dependent upon them. */
2799 /* Process default font as well, since fringe widths depends on it. */
2800 for (p = 0; p < i; p++)
2801 {
2802 Lisp_Object prop, val;
2803
2804 prop = parms[p];
2805 val = values[p];
2806 if (EQ (prop, Qforeground_color)
2807 || EQ (prop, Qbackground_color)
2808 || EQ (prop, Qfont))
2809 {
2810 register Lisp_Object param_index, old_value;
2811
2812 old_value = get_frame_param (f, prop);
2813 if (NILP (Fequal (val, old_value)))
2814 {
2815 store_frame_param (f, prop, val);
2816
2817 param_index = Fget (prop, Qx_frame_parameter);
2818 if (NATNUMP (param_index)
2819 && (XFASTINT (param_index)
2820 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2821 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2822 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2823 }
2824 }
2825 }
2826
2827 /* Now process them in reverse of specified order. */
2828 while (i-- != 0)
2829 {
2830 Lisp_Object prop, val;
2831
2832 prop = parms[i];
2833 val = values[i];
2834
2835 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2836 {
2837 size_changed = 1;
2838 width = XFASTINT (val);
2839 }
2840 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2841 {
2842 size_changed = 1;
2843 height = XFASTINT (val);
2844 }
2845 else if (EQ (prop, Qtop))
2846 top = val;
2847 else if (EQ (prop, Qleft))
2848 left = val;
2849 else if (EQ (prop, Qicon_top))
2850 icon_top = val;
2851 else if (EQ (prop, Qicon_left))
2852 icon_left = val;
2853 else if (EQ (prop, Qforeground_color)
2854 || EQ (prop, Qbackground_color)
2855 || EQ (prop, Qfont))
2856 /* Processed above. */
2857 continue;
2858 else
2859 {
2860 register Lisp_Object param_index, old_value;
2861
2862 old_value = get_frame_param (f, prop);
2863
2864 store_frame_param (f, prop, val);
2865
2866 param_index = Fget (prop, Qx_frame_parameter);
2867 if (NATNUMP (param_index)
2868 && (XFASTINT (param_index)
2869 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2870 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2871 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2872 }
2873 }
2874
2875 /* Don't die if just one of these was set. */
2876 if (! TYPE_RANGED_INTEGERP (int, left))
2877 {
2878 left_no_change = 1;
2879 if (f->left_pos < 0)
2880 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2881 else
2882 XSETINT (left, f->left_pos);
2883 }
2884 if (! TYPE_RANGED_INTEGERP (int, top))
2885 {
2886 top_no_change = 1;
2887 if (f->top_pos < 0)
2888 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2889 else
2890 XSETINT (top, f->top_pos);
2891 }
2892
2893 /* If one of the icon positions was not set, preserve or default it. */
2894 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2895 {
2896 icon_left_no_change = 1;
2897 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2898 if (NILP (icon_left))
2899 XSETINT (icon_left, 0);
2900 }
2901 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2902 {
2903 icon_top_no_change = 1;
2904 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2905 if (NILP (icon_top))
2906 XSETINT (icon_top, 0);
2907 }
2908
2909 /* Don't set these parameters unless they've been explicitly
2910 specified. The window might be mapped or resized while we're in
2911 this function, and we don't want to override that unless the lisp
2912 code has asked for it.
2913
2914 Don't set these parameters unless they actually differ from the
2915 window's current parameters; the window may not actually exist
2916 yet. */
2917 {
2918 Lisp_Object frame;
2919
2920 check_frame_size (f, &height, &width);
2921
2922 XSETFRAME (frame, f);
2923
2924 if (size_changed
2925 && (width != FRAME_COLS (f)
2926 || height != FRAME_LINES (f)
2927 || f->new_text_lines || f->new_text_cols))
2928 Fset_frame_size (frame, make_number (width), make_number (height));
2929
2930 if ((!NILP (left) || !NILP (top))
2931 && ! (left_no_change && top_no_change)
2932 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2933 && NUMBERP (top) && XINT (top) == f->top_pos))
2934 {
2935 int leftpos = 0;
2936 int toppos = 0;
2937
2938 /* Record the signs. */
2939 f->size_hint_flags &= ~ (XNegative | YNegative);
2940 if (EQ (left, Qminus))
2941 f->size_hint_flags |= XNegative;
2942 else if (TYPE_RANGED_INTEGERP (int, left))
2943 {
2944 leftpos = XINT (left);
2945 if (leftpos < 0)
2946 f->size_hint_flags |= XNegative;
2947 }
2948 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2949 && CONSP (XCDR (left))
2950 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2951 {
2952 leftpos = - XINT (XCAR (XCDR (left)));
2953 f->size_hint_flags |= XNegative;
2954 }
2955 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2956 && CONSP (XCDR (left))
2957 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2958 {
2959 leftpos = XINT (XCAR (XCDR (left)));
2960 }
2961
2962 if (EQ (top, Qminus))
2963 f->size_hint_flags |= YNegative;
2964 else if (TYPE_RANGED_INTEGERP (int, top))
2965 {
2966 toppos = XINT (top);
2967 if (toppos < 0)
2968 f->size_hint_flags |= YNegative;
2969 }
2970 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2971 && CONSP (XCDR (top))
2972 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2973 {
2974 toppos = - XINT (XCAR (XCDR (top)));
2975 f->size_hint_flags |= YNegative;
2976 }
2977 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2978 && CONSP (XCDR (top))
2979 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
2980 {
2981 toppos = XINT (XCAR (XCDR (top)));
2982 }
2983
2984
2985 /* Store the numeric value of the position. */
2986 f->top_pos = toppos;
2987 f->left_pos = leftpos;
2988
2989 f->win_gravity = NorthWestGravity;
2990
2991 /* Actually set that position, and convert to absolute. */
2992 x_set_offset (f, leftpos, toppos, -1);
2993 }
2994
2995 if ((!NILP (icon_left) || !NILP (icon_top))
2996 && ! (icon_left_no_change && icon_top_no_change))
2997 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2998 }
2999
3000 UNGCPRO;
3001 }
3002
3003
3004 /* Insert a description of internally-recorded parameters of frame X
3005 into the parameter alist *ALISTPTR that is to be given to the user.
3006 Only parameters that are specific to the X window system
3007 and whose values are not correctly recorded in the frame's
3008 param_alist need to be considered here. */
3009
3010 void
3011 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3012 {
3013 char buf[16];
3014 Lisp_Object tem;
3015 unsigned long w;
3016
3017 /* Represent negative positions (off the top or left screen edge)
3018 in a way that Fmodify_frame_parameters will understand correctly. */
3019 XSETINT (tem, f->left_pos);
3020 if (f->left_pos >= 0)
3021 store_in_alist (alistptr, Qleft, tem);
3022 else
3023 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3024
3025 XSETINT (tem, f->top_pos);
3026 if (f->top_pos >= 0)
3027 store_in_alist (alistptr, Qtop, tem);
3028 else
3029 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3030
3031 store_in_alist (alistptr, Qborder_width,
3032 make_number (f->border_width));
3033 store_in_alist (alistptr, Qinternal_border_width,
3034 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3035 store_in_alist (alistptr, Qleft_fringe,
3036 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3037 store_in_alist (alistptr, Qright_fringe,
3038 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3039 store_in_alist (alistptr, Qscroll_bar_width,
3040 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3041 ? make_number (0)
3042 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3043 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3044 /* nil means "use default width"
3045 for non-toolkit scroll bar.
3046 ruler-mode.el depends on this. */
3047 : Qnil));
3048 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3049 MS-Windows it returns a value whose type is HANDLE, which is
3050 actually a pointer. Explicit casting avoids compiler
3051 warnings. */
3052 w = (unsigned long) FRAME_X_WINDOW (f);
3053 sprintf (buf, "%lu", w);
3054 store_in_alist (alistptr, Qwindow_id,
3055 build_string (buf));
3056 #ifdef HAVE_X_WINDOWS
3057 #ifdef USE_X_TOOLKIT
3058 /* Tooltip frame may not have this widget. */
3059 if (FRAME_X_OUTPUT (f)->widget)
3060 #endif
3061 {
3062 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3063 sprintf (buf, "%lu", w);
3064 }
3065 store_in_alist (alistptr, Qouter_window_id,
3066 build_string (buf));
3067 #endif
3068 store_in_alist (alistptr, Qicon_name, f->icon_name);
3069 FRAME_SAMPLE_VISIBILITY (f);
3070 store_in_alist (alistptr, Qvisibility,
3071 (FRAME_VISIBLE_P (f) ? Qt
3072 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3073 store_in_alist (alistptr, Qdisplay,
3074 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3075
3076 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3077 tem = Qnil;
3078 else
3079 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3080 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3081 store_in_alist (alistptr, Qparent_id, tem);
3082 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3083 }
3084
3085
3086 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3087 the previous value of that parameter, NEW_VALUE is the new value. */
3088
3089 void
3090 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3091 {
3092 if (NILP (new_value))
3093 f->want_fullscreen = FULLSCREEN_NONE;
3094 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3095 f->want_fullscreen = FULLSCREEN_BOTH;
3096 else if (EQ (new_value, Qfullwidth))
3097 f->want_fullscreen = FULLSCREEN_WIDTH;
3098 else if (EQ (new_value, Qfullheight))
3099 f->want_fullscreen = FULLSCREEN_HEIGHT;
3100 else if (EQ (new_value, Qmaximized))
3101 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3102
3103 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3104 FRAME_TERMINAL (f)->fullscreen_hook (f);
3105 }
3106
3107
3108 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3109 the previous value of that parameter, NEW_VALUE is the new value. */
3110
3111 void
3112 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3113 {
3114 if (NILP (new_value))
3115 f->extra_line_spacing = 0;
3116 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3117 f->extra_line_spacing = XFASTINT (new_value);
3118 else
3119 signal_error ("Invalid line-spacing", new_value);
3120 if (FRAME_VISIBLE_P (f))
3121 redraw_frame (f);
3122 }
3123
3124
3125 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3126 the previous value of that parameter, NEW_VALUE is the new value. */
3127
3128 void
3129 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3130 {
3131 Lisp_Object bgcolor;
3132
3133 if (NILP (new_value))
3134 f->gamma = 0;
3135 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3136 /* The value 0.4545 is the normal viewing gamma. */
3137 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3138 else
3139 signal_error ("Invalid screen-gamma", new_value);
3140
3141 /* Apply the new gamma value to the frame background. */
3142 bgcolor = Fassq (Qbackground_color, f->param_alist);
3143 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3144 {
3145 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3146 if (NATNUMP (parm_index)
3147 && (XFASTINT (parm_index)
3148 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3149 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3150 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3151 (f, bgcolor, Qnil);
3152 }
3153
3154 Fclear_face_cache (Qnil);
3155 }
3156
3157
3158 void
3159 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3160 {
3161 Lisp_Object font_object, font_param = Qnil;
3162 int fontset = -1;
3163
3164 /* Set the frame parameter back to the old value because we may
3165 fail to use ARG as the new parameter value. */
3166 store_frame_param (f, Qfont, oldval);
3167
3168 /* ARG is a fontset name, a font name, a cons of fontset name and a
3169 font object, or a font object. In the last case, this function
3170 never fail. */
3171 if (STRINGP (arg))
3172 {
3173 font_param = arg;
3174 fontset = fs_query_fontset (arg, 0);
3175 if (fontset < 0)
3176 {
3177 font_object = font_open_by_name (f, SSDATA (arg));
3178 if (NILP (font_object))
3179 error ("Font `%s' is not defined", SSDATA (arg));
3180 arg = AREF (font_object, FONT_NAME_INDEX);
3181 }
3182 else if (fontset > 0)
3183 {
3184 Lisp_Object ascii_font = fontset_ascii (fontset);
3185
3186 font_object = font_open_by_name (f, SSDATA (ascii_font));
3187 if (NILP (font_object))
3188 error ("Font `%s' is not defined", SDATA (arg));
3189 arg = AREF (font_object, FONT_NAME_INDEX);
3190 }
3191 else
3192 error ("The default fontset can't be used for a frame font");
3193 }
3194 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3195 {
3196 /* This is the case that the ASCII font of F's fontset XCAR
3197 (arg) is changed to the font XCDR (arg) by
3198 `set-fontset-font'. */
3199 fontset = fs_query_fontset (XCAR (arg), 0);
3200 if (fontset < 0)
3201 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3202 font_object = XCDR (arg);
3203 arg = AREF (font_object, FONT_NAME_INDEX);
3204 font_param = Ffont_get (font_object, QCname);
3205 }
3206 else if (FONT_OBJECT_P (arg))
3207 {
3208 font_object = arg;
3209 font_param = Ffont_get (font_object, QCname);
3210 /* This is to store the XLFD font name in the frame parameter for
3211 backward compatibility. We should store the font-object
3212 itself in the future. */
3213 arg = AREF (font_object, FONT_NAME_INDEX);
3214 fontset = FRAME_FONTSET (f);
3215 /* Check if we can use the current fontset. If not, set FONTSET
3216 to -1 to generate a new fontset from FONT-OBJECT. */
3217 if (fontset >= 0)
3218 {
3219 Lisp_Object ascii_font = fontset_ascii (fontset);
3220 Lisp_Object spec = font_spec_from_name (ascii_font);
3221
3222 if (! font_match_p (spec, font_object))
3223 fontset = -1;
3224 }
3225 }
3226 else
3227 signal_error ("Invalid font", arg);
3228
3229 if (! NILP (Fequal (font_object, oldval)))
3230 return;
3231
3232 x_new_font (f, font_object, fontset);
3233 store_frame_param (f, Qfont, arg);
3234 #ifdef HAVE_X_WINDOWS
3235 store_frame_param (f, Qfont_param, font_param);
3236 #endif
3237 /* Recalculate toolbar height. */
3238 f->n_tool_bar_rows = 0;
3239 /* Ensure we redraw it. */
3240 clear_current_matrices (f);
3241
3242 recompute_basic_faces (f);
3243
3244 do_pending_window_change (0);
3245
3246 /* We used to call face-set-after-frame-default here, but it leads to
3247 recursive calls (since that function can set the `default' face's
3248 font which in turns changes the frame's `font' parameter).
3249 Also I don't know what this call is meant to do, but it seems the
3250 wrong way to do it anyway (it does a lot more work than what seems
3251 reasonable in response to a change to `font'). */
3252 }
3253
3254
3255 void
3256 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3257 {
3258 if (! NILP (new_value)
3259 && !CONSP (new_value))
3260 {
3261 char *p0, *p1;
3262
3263 CHECK_STRING (new_value);
3264 p0 = p1 = SSDATA (new_value);
3265 new_value = Qnil;
3266 while (*p0)
3267 {
3268 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3269 if (p0 < p1)
3270 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3271 new_value);
3272 if (*p1)
3273 {
3274 int c;
3275
3276 while ((c = *++p1) && isspace (c));
3277 }
3278 p0 = p1;
3279 }
3280 new_value = Fnreverse (new_value);
3281 }
3282
3283 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3284 return;
3285
3286 if (FRAME_FONT (f))
3287 free_all_realized_faces (Qnil);
3288
3289 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3290 if (NILP (new_value))
3291 {
3292 if (NILP (old_value))
3293 error ("No font backend available");
3294 font_update_drivers (f, old_value);
3295 error ("None of specified font backends are available");
3296 }
3297 store_frame_param (f, Qfont_backend, new_value);
3298
3299 if (FRAME_FONT (f))
3300 {
3301 Lisp_Object frame;
3302
3303 XSETFRAME (frame, f);
3304 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3305 ++face_change_count;
3306 ++windows_or_buffers_changed;
3307 }
3308 }
3309
3310
3311 void
3312 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3313 {
3314 compute_fringe_widths (f, 1);
3315 #ifdef HAVE_X_WINDOWS
3316 /* Must adjust this so window managers report correct number of columns. */
3317 if (FRAME_X_WINDOW (f) != 0)
3318 x_wm_set_size_hint (f, 0, 0);
3319 #endif
3320 }
3321
3322 void
3323 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3324 {
3325 CHECK_TYPE_RANGED_INTEGER (int, arg);
3326
3327 if (XINT (arg) == f->border_width)
3328 return;
3329
3330 if (FRAME_X_WINDOW (f) != 0)
3331 error ("Cannot change the border width of a frame");
3332
3333 f->border_width = XINT (arg);
3334 }
3335
3336 void
3337 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3338 {
3339 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3340
3341 CHECK_TYPE_RANGED_INTEGER (int, arg);
3342 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3343 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3344 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3345
3346 #ifdef USE_X_TOOLKIT
3347 if (FRAME_X_OUTPUT (f)->edit_widget)
3348 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3349 #endif
3350
3351 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3352 return;
3353
3354 if (FRAME_X_WINDOW (f) != 0)
3355 {
3356 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3357 SET_FRAME_GARBAGED (f);
3358 do_pending_window_change (0);
3359 }
3360 else
3361 SET_FRAME_GARBAGED (f);
3362 }
3363
3364 void
3365 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3366 {
3367 Lisp_Object frame;
3368 XSETFRAME (frame, f);
3369
3370 if (NILP (value))
3371 Fmake_frame_invisible (frame, Qt);
3372 else if (EQ (value, Qicon))
3373 Ficonify_frame (frame);
3374 else
3375 Fmake_frame_visible (frame);
3376 }
3377
3378 void
3379 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3380 {
3381 f->auto_raise = !EQ (Qnil, arg);
3382 }
3383
3384 void
3385 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3386 {
3387 f->auto_lower = !EQ (Qnil, arg);
3388 }
3389
3390 void
3391 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3392 {
3393 f->no_split = !NILP (arg);
3394 }
3395
3396 void
3397 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3398 {
3399 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3400 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3401 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3402 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3403 {
3404 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3405 = (NILP (arg)
3406 ? vertical_scroll_bar_none
3407 : EQ (Qleft, arg)
3408 ? vertical_scroll_bar_left
3409 : EQ (Qright, arg)
3410 ? vertical_scroll_bar_right
3411 : EQ (Qleft, Vdefault_frame_scroll_bars)
3412 ? vertical_scroll_bar_left
3413 : EQ (Qright, Vdefault_frame_scroll_bars)
3414 ? vertical_scroll_bar_right
3415 : vertical_scroll_bar_none);
3416
3417 /* We set this parameter before creating the X window for the
3418 frame, so we can get the geometry right from the start.
3419 However, if the window hasn't been created yet, we shouldn't
3420 call x_set_window_size. */
3421 if (FRAME_X_WINDOW (f))
3422 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3423 do_pending_window_change (0);
3424 }
3425 }
3426
3427 void
3428 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3429 {
3430 int wid = FRAME_COLUMN_WIDTH (f);
3431
3432 if (NILP (arg))
3433 {
3434 x_set_scroll_bar_default_width (f);
3435
3436 if (FRAME_X_WINDOW (f))
3437 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3438 do_pending_window_change (0);
3439 }
3440 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3441 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3442 {
3443 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3444 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3445
3446 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3447 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3448 if (FRAME_X_WINDOW (f))
3449 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3450 do_pending_window_change (0);
3451 }
3452
3453 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3454 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3455 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3456 }
3457
3458
3459
3460 /* Return non-nil if frame F wants a bitmap icon. */
3461
3462 Lisp_Object
3463 x_icon_type (FRAME_PTR f)
3464 {
3465 Lisp_Object tem;
3466
3467 tem = assq_no_quit (Qicon_type, f->param_alist);
3468 if (CONSP (tem))
3469 return XCDR (tem);
3470 else
3471 return Qnil;
3472 }
3473
3474 void
3475 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3476 {
3477 double alpha = 1.0;
3478 double newval[2];
3479 int i;
3480 Lisp_Object item;
3481
3482 for (i = 0; i < 2; i++)
3483 {
3484 newval[i] = 1.0;
3485 if (CONSP (arg))
3486 {
3487 item = CAR (arg);
3488 arg = CDR (arg);
3489 }
3490 else
3491 item = arg;
3492
3493 if (NILP (item))
3494 alpha = - 1.0;
3495 else if (FLOATP (item))
3496 {
3497 alpha = XFLOAT_DATA (item);
3498 if (alpha < 0.0 || 1.0 < alpha)
3499 args_out_of_range (make_float (0.0), make_float (1.0));
3500 }
3501 else if (INTEGERP (item))
3502 {
3503 EMACS_INT ialpha = XINT (item);
3504 if (ialpha < 0 || 100 < ialpha)
3505 args_out_of_range (make_number (0), make_number (100));
3506 else
3507 alpha = ialpha / 100.0;
3508 }
3509 else
3510 wrong_type_argument (Qnumberp, item);
3511 newval[i] = alpha;
3512 }
3513
3514 for (i = 0; i < 2; i++)
3515 f->alpha[i] = newval[i];
3516
3517 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3518 BLOCK_INPUT;
3519 x_set_frame_alpha (f);
3520 UNBLOCK_INPUT;
3521 #endif
3522
3523 return;
3524 }
3525
3526 \f
3527 /* Subroutines of creating an X frame. */
3528
3529 /* Make sure that Vx_resource_name is set to a reasonable value.
3530 Fix it up, or set it to `emacs' if it is too hopeless. */
3531
3532 void
3533 validate_x_resource_name (void)
3534 {
3535 ptrdiff_t len = 0;
3536 /* Number of valid characters in the resource name. */
3537 ptrdiff_t good_count = 0;
3538 /* Number of invalid characters in the resource name. */
3539 ptrdiff_t bad_count = 0;
3540 Lisp_Object new;
3541 ptrdiff_t i;
3542
3543 if (!STRINGP (Vx_resource_class))
3544 Vx_resource_class = build_string (EMACS_CLASS);
3545
3546 if (STRINGP (Vx_resource_name))
3547 {
3548 unsigned char *p = SDATA (Vx_resource_name);
3549
3550 len = SBYTES (Vx_resource_name);
3551
3552 /* Only letters, digits, - and _ are valid in resource names.
3553 Count the valid characters and count the invalid ones. */
3554 for (i = 0; i < len; i++)
3555 {
3556 int c = p[i];
3557 if (! ((c >= 'a' && c <= 'z')
3558 || (c >= 'A' && c <= 'Z')
3559 || (c >= '0' && c <= '9')
3560 || c == '-' || c == '_'))
3561 bad_count++;
3562 else
3563 good_count++;
3564 }
3565 }
3566 else
3567 /* Not a string => completely invalid. */
3568 bad_count = 5, good_count = 0;
3569
3570 /* If name is valid already, return. */
3571 if (bad_count == 0)
3572 return;
3573
3574 /* If name is entirely invalid, or nearly so, or is so implausibly
3575 large that alloca might not work, use `emacs'. */
3576 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3577 {
3578 Vx_resource_name = build_string ("emacs");
3579 return;
3580 }
3581
3582 /* Name is partly valid. Copy it and replace the invalid characters
3583 with underscores. */
3584
3585 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3586
3587 for (i = 0; i < len; i++)
3588 {
3589 int c = SREF (new, i);
3590 if (! ((c >= 'a' && c <= 'z')
3591 || (c >= 'A' && c <= 'Z')
3592 || (c >= '0' && c <= '9')
3593 || c == '-' || c == '_'))
3594 SSET (new, i, '_');
3595 }
3596 }
3597
3598
3599 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3600 extern Display_Info *check_x_display_info (Lisp_Object);
3601
3602
3603 /* Get specified attribute from resource database RDB.
3604 See Fx_get_resource below for other parameters. */
3605
3606 static Lisp_Object
3607 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3608 {
3609 register char *value;
3610 char *name_key;
3611 char *class_key;
3612
3613 CHECK_STRING (attribute);
3614 CHECK_STRING (class);
3615
3616 if (!NILP (component))
3617 CHECK_STRING (component);
3618 if (!NILP (subclass))
3619 CHECK_STRING (subclass);
3620 if (NILP (component) != NILP (subclass))
3621 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3622
3623 validate_x_resource_name ();
3624
3625 /* Allocate space for the components, the dots which separate them,
3626 and the final '\0'. Make them big enough for the worst case. */
3627 name_key = (char *) alloca (SBYTES (Vx_resource_name)
3628 + (STRINGP (component)
3629 ? SBYTES (component) : 0)
3630 + SBYTES (attribute)
3631 + 3);
3632
3633 class_key = (char *) alloca (SBYTES (Vx_resource_class)
3634 + SBYTES (class)
3635 + (STRINGP (subclass)
3636 ? SBYTES (subclass) : 0)
3637 + 3);
3638
3639 /* Start with emacs.FRAMENAME for the name (the specific one)
3640 and with `Emacs' for the class key (the general one). */
3641 strcpy (name_key, SSDATA (Vx_resource_name));
3642 strcpy (class_key, SSDATA (Vx_resource_class));
3643
3644 strcat (class_key, ".");
3645 strcat (class_key, SSDATA (class));
3646
3647 if (!NILP (component))
3648 {
3649 strcat (class_key, ".");
3650 strcat (class_key, SSDATA (subclass));
3651
3652 strcat (name_key, ".");
3653 strcat (name_key, SSDATA (component));
3654 }
3655
3656 strcat (name_key, ".");
3657 strcat (name_key, SSDATA (attribute));
3658
3659 value = x_get_string_resource (rdb, name_key, class_key);
3660
3661 if (value != (char *) 0 && *value)
3662 return build_string (value);
3663 else
3664 return Qnil;
3665 }
3666
3667
3668 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3669 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3670 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3671 class, where INSTANCE is the name under which Emacs was invoked, or
3672 the name specified by the `-name' or `-rn' command-line arguments.
3673
3674 The optional arguments COMPONENT and SUBCLASS add to the key and the
3675 class, respectively. You must specify both of them or neither.
3676 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3677 and the class is `Emacs.CLASS.SUBCLASS'. */)
3678 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3679 {
3680 #ifdef HAVE_X_WINDOWS
3681 check_x ();
3682 #endif
3683
3684 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3685 attribute, class, component, subclass);
3686 }
3687
3688 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3689
3690 Lisp_Object
3691 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3692 {
3693 return xrdb_get_resource (dpyinfo->xrdb,
3694 attribute, class, component, subclass);
3695 }
3696
3697 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3698 /* Used when C code wants a resource value. */
3699 /* Called from oldXMenu/Create.c. */
3700 char *
3701 x_get_resource_string (const char *attribute, const char *class)
3702 {
3703 char *name_key;
3704 char *class_key;
3705 char *result;
3706 struct frame *sf = SELECTED_FRAME ();
3707 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3708 USE_SAFE_ALLOCA;
3709
3710 /* Allocate space for the components, the dots which separate them,
3711 and the final '\0'. */
3712 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3713 class_key = (char *) alloca ((sizeof (EMACS_CLASS) - 1)
3714 + strlen (class) + 2);
3715
3716 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3717 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3718
3719 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3720 name_key, class_key);
3721 SAFE_FREE ();
3722 return result;
3723 }
3724 #endif
3725
3726 /* Return the value of parameter PARAM.
3727
3728 First search ALIST, then Vdefault_frame_alist, then the X defaults
3729 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3730
3731 Convert the resource to the type specified by desired_type.
3732
3733 If no default is specified, return Qunbound. If you call
3734 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3735 and don't let it get stored in any Lisp-visible variables! */
3736
3737 Lisp_Object
3738 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3739 const char *attribute, const char *class, enum resource_types type)
3740 {
3741 register Lisp_Object tem;
3742
3743 tem = Fassq (param, alist);
3744
3745 if (!NILP (tem))
3746 {
3747 /* If we find this parm in ALIST, clear it out
3748 so that it won't be "left over" at the end. */
3749 Lisp_Object tail;
3750 XSETCAR (tem, Qnil);
3751 /* In case the parameter appears more than once in the alist,
3752 clear it out. */
3753 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3754 if (CONSP (XCAR (tail))
3755 && EQ (XCAR (XCAR (tail)), param))
3756 XSETCAR (XCAR (tail), Qnil);
3757 }
3758 else
3759 tem = Fassq (param, Vdefault_frame_alist);
3760
3761 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3762 look in the X resources. */
3763 if (EQ (tem, Qnil))
3764 {
3765 if (attribute && dpyinfo)
3766 {
3767 tem = display_x_get_resource (dpyinfo,
3768 build_string (attribute),
3769 build_string (class),
3770 Qnil, Qnil);
3771
3772 if (NILP (tem))
3773 return Qunbound;
3774
3775 switch (type)
3776 {
3777 case RES_TYPE_NUMBER:
3778 return make_number (atoi (SSDATA (tem)));
3779
3780 case RES_TYPE_BOOLEAN_NUMBER:
3781 if (!strcmp (SSDATA (tem), "on")
3782 || !strcmp (SSDATA (tem), "true"))
3783 return make_number (1);
3784 return make_number (atoi (SSDATA (tem)));
3785 break;
3786
3787 case RES_TYPE_FLOAT:
3788 return make_float (atof (SSDATA (tem)));
3789
3790 case RES_TYPE_BOOLEAN:
3791 tem = Fdowncase (tem);
3792 if (!strcmp (SSDATA (tem), "on")
3793 #ifdef HAVE_NS
3794 || !strcmp (SSDATA (tem), "yes")
3795 #endif
3796 || !strcmp (SSDATA (tem), "true"))
3797 return Qt;
3798 else
3799 return Qnil;
3800
3801 case RES_TYPE_STRING:
3802 return tem;
3803
3804 case RES_TYPE_SYMBOL:
3805 /* As a special case, we map the values `true' and `on'
3806 to Qt, and `false' and `off' to Qnil. */
3807 {
3808 Lisp_Object lower;
3809 lower = Fdowncase (tem);
3810 if (!strcmp (SSDATA (lower), "on")
3811 #ifdef HAVE_NS
3812 || !strcmp (SSDATA (lower), "yes")
3813 #endif
3814 || !strcmp (SSDATA (lower), "true"))
3815 return Qt;
3816 else if (!strcmp (SSDATA (lower), "off")
3817 #ifdef HAVE_NS
3818 || !strcmp (SSDATA (lower), "no")
3819 #endif
3820 || !strcmp (SSDATA (lower), "false"))
3821 return Qnil;
3822 else
3823 return Fintern (tem, Qnil);
3824 }
3825
3826 default:
3827 abort ();
3828 }
3829 }
3830 else
3831 return Qunbound;
3832 }
3833 return Fcdr (tem);
3834 }
3835
3836 static Lisp_Object
3837 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3838 const char *attribute, const char *class,
3839 enum resource_types type)
3840 {
3841 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3842 alist, param, attribute, class, type);
3843 }
3844
3845 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3846
3847 Lisp_Object
3848 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3849 Lisp_Object param,
3850 const char *attribute, const char *class,
3851 enum resource_types type)
3852 {
3853 Lisp_Object value;
3854
3855 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3856 attribute, class, type);
3857 if (! NILP (value) && ! EQ (value, Qunbound))
3858 store_frame_param (f, param, value);
3859
3860 return value;
3861 }
3862
3863
3864 /* Record in frame F the specified or default value according to ALIST
3865 of the parameter named PROP (a Lisp symbol).
3866 If no value is specified for PROP, look for an X default for XPROP
3867 on the frame named NAME.
3868 If that is not found either, use the value DEFLT. */
3869
3870 Lisp_Object
3871 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3872 Lisp_Object deflt, const char *xprop, const char *xclass,
3873 enum resource_types type)
3874 {
3875 Lisp_Object tem;
3876
3877 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3878 if (EQ (tem, Qunbound))
3879 tem = deflt;
3880 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3881 return tem;
3882 }
3883
3884
3885
3886 \f
3887 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3888 make-docfile: the documentation string in ns-win.el was used for
3889 x-parse-geometry even in non-NS builds.
3890
3891 With two definitions of x-parse-geometry in this file, various
3892 things still get confused (eg M-x apropos documentation), so that
3893 it is best if the two definitions just share the same doc-string.
3894 */
3895 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3896 doc: /* Parse a display geometry string STRING.
3897 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3898 The properties returned may include `top', `left', `height', and `width'.
3899 For X, the value of `left' or `top' may be an integer,
3900 or a list (+ N) meaning N pixels relative to top/left corner,
3901 or a list (- N) meaning -N pixels relative to bottom/right corner.
3902 On Nextstep, this just calls `ns-parse-geometry'. */)
3903 (Lisp_Object string)
3904 {
3905 #ifdef HAVE_NS
3906 call1 (Qns_parse_geometry, string);
3907 #else
3908 int geometry, x, y;
3909 unsigned int width, height;
3910 Lisp_Object result;
3911
3912 CHECK_STRING (string);
3913
3914 geometry = XParseGeometry (SSDATA (string),
3915 &x, &y, &width, &height);
3916 result = Qnil;
3917 if (geometry & XValue)
3918 {
3919 Lisp_Object element;
3920
3921 if (x >= 0 && (geometry & XNegative))
3922 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3923 else if (x < 0 && ! (geometry & XNegative))
3924 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3925 else
3926 element = Fcons (Qleft, make_number (x));
3927 result = Fcons (element, result);
3928 }
3929
3930 if (geometry & YValue)
3931 {
3932 Lisp_Object element;
3933
3934 if (y >= 0 && (geometry & YNegative))
3935 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3936 else if (y < 0 && ! (geometry & YNegative))
3937 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3938 else
3939 element = Fcons (Qtop, make_number (y));
3940 result = Fcons (element, result);
3941 }
3942
3943 if (geometry & WidthValue)
3944 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3945 if (geometry & HeightValue)
3946 result = Fcons (Fcons (Qheight, make_number (height)), result);
3947
3948 return result;
3949 #endif /* HAVE_NS */
3950 }
3951
3952
3953 /* Calculate the desired size and position of frame F.
3954 Return the flags saying which aspects were specified.
3955
3956 Also set the win_gravity and size_hint_flags of F.
3957
3958 Adjust height for toolbar if TOOLBAR_P is 1.
3959
3960 This function does not make the coordinates positive. */
3961
3962 #define DEFAULT_ROWS 35
3963 #define DEFAULT_COLS 80
3964
3965 int
3966 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
3967 {
3968 register Lisp_Object tem0, tem1, tem2;
3969 long window_prompting = 0;
3970 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3971
3972 /* Default values if we fall through.
3973 Actually, if that happens we should get
3974 window manager prompting. */
3975 SET_FRAME_COLS (f, DEFAULT_COLS);
3976 FRAME_LINES (f) = DEFAULT_ROWS;
3977 /* Window managers expect that if program-specified
3978 positions are not (0,0), they're intentional, not defaults. */
3979 f->top_pos = 0;
3980 f->left_pos = 0;
3981
3982 /* Ensure that old new_text_cols and new_text_lines will not override the
3983 values set here. */
3984 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3985 f->new_text_cols = f->new_text_lines = 0;
3986
3987 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3988 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3989 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3990 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3991 {
3992 if (!EQ (tem0, Qunbound))
3993 {
3994 CHECK_NUMBER (tem0);
3995 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
3996 xsignal1 (Qargs_out_of_range, tem0);
3997 FRAME_LINES (f) = XINT (tem0);
3998 }
3999 if (!EQ (tem1, Qunbound))
4000 {
4001 CHECK_NUMBER (tem1);
4002 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4003 xsignal1 (Qargs_out_of_range, tem1);
4004 SET_FRAME_COLS (f, XINT (tem1));
4005 }
4006 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4007 window_prompting |= USSize;
4008 else
4009 window_prompting |= PSize;
4010 }
4011
4012 f->scroll_bar_actual_width
4013 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4014
4015 /* This used to be done _before_ calling x_figure_window_size, but
4016 since the height is reset here, this was really a no-op. I
4017 assume that moving it here does what Gerd intended (although he
4018 no longer can remember what that was... ++KFS, 2003-03-25. */
4019
4020 /* Add the tool-bar height to the initial frame height so that the
4021 user gets a text display area of the size he specified with -g or
4022 via .Xdefaults. Later changes of the tool-bar height don't
4023 change the frame size. This is done so that users can create
4024 tall Emacs frames without having to guess how tall the tool-bar
4025 will get. */
4026 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4027 {
4028 int margin, relief, bar_height;
4029
4030 relief = (tool_bar_button_relief >= 0
4031 ? tool_bar_button_relief
4032 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4033
4034 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4035 margin = XFASTINT (Vtool_bar_button_margin);
4036 else if (CONSP (Vtool_bar_button_margin)
4037 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4038 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4039 else
4040 margin = 0;
4041
4042 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4043 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4044 }
4045
4046 compute_fringe_widths (f, 0);
4047
4048 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4049 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4050
4051 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4052 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4053 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4054 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4055 {
4056 if (EQ (tem0, Qminus))
4057 {
4058 f->top_pos = 0;
4059 window_prompting |= YNegative;
4060 }
4061 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4062 && CONSP (XCDR (tem0))
4063 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4064 {
4065 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4066 window_prompting |= YNegative;
4067 }
4068 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4069 && CONSP (XCDR (tem0))
4070 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4071 {
4072 f->top_pos = XINT (XCAR (XCDR (tem0)));
4073 }
4074 else if (EQ (tem0, Qunbound))
4075 f->top_pos = 0;
4076 else
4077 {
4078 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4079 f->top_pos = XINT (tem0);
4080 if (f->top_pos < 0)
4081 window_prompting |= YNegative;
4082 }
4083
4084 if (EQ (tem1, Qminus))
4085 {
4086 f->left_pos = 0;
4087 window_prompting |= XNegative;
4088 }
4089 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4090 && CONSP (XCDR (tem1))
4091 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4092 {
4093 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4094 window_prompting |= XNegative;
4095 }
4096 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4097 && CONSP (XCDR (tem1))
4098 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4099 {
4100 f->left_pos = XINT (XCAR (XCDR (tem1)));
4101 }
4102 else if (EQ (tem1, Qunbound))
4103 f->left_pos = 0;
4104 else
4105 {
4106 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4107 f->left_pos = XINT (tem1);
4108 if (f->left_pos < 0)
4109 window_prompting |= XNegative;
4110 }
4111
4112 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4113 window_prompting |= USPosition;
4114 else
4115 window_prompting |= PPosition;
4116 }
4117
4118 if (window_prompting & XNegative)
4119 {
4120 if (window_prompting & YNegative)
4121 f->win_gravity = SouthEastGravity;
4122 else
4123 f->win_gravity = NorthEastGravity;
4124 }
4125 else
4126 {
4127 if (window_prompting & YNegative)
4128 f->win_gravity = SouthWestGravity;
4129 else
4130 f->win_gravity = NorthWestGravity;
4131 }
4132
4133 f->size_hint_flags = window_prompting;
4134
4135 return window_prompting;
4136 }
4137
4138
4139
4140 #endif /* HAVE_WINDOW_SYSTEM */
4141
4142 void
4143 frame_make_pointer_invisible (void)
4144 {
4145 if (! NILP (Vmake_pointer_invisible))
4146 {
4147 struct frame *f;
4148 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4149 return;
4150
4151 f = SELECTED_FRAME ();
4152 if (f && !f->pointer_invisible
4153 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4154 {
4155 f->mouse_moved = 0;
4156 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4157 f->pointer_invisible = 1;
4158 }
4159 }
4160 }
4161
4162 void
4163 frame_make_pointer_visible (void)
4164 {
4165 /* We don't check Vmake_pointer_invisible here in case the
4166 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4167 struct frame *f;
4168
4169 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4170 return;
4171
4172 f = SELECTED_FRAME ();
4173 if (f && f->pointer_invisible && f->mouse_moved
4174 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4175 {
4176 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4177 f->pointer_invisible = 0;
4178 }
4179 }
4180
4181 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4182 Sframe_pointer_visible_p, 0, 1, 0,
4183 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4184 Otherwise it returns nil. FRAME omitted or nil means the
4185 selected frame. This is useful when `make-pointer-invisible' is set. */)
4186 (Lisp_Object frame)
4187 {
4188 if (NILP (frame))
4189 frame = selected_frame;
4190
4191 CHECK_FRAME (frame);
4192
4193 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4194 }
4195
4196 \f
4197 /***********************************************************************
4198 Initialization
4199 ***********************************************************************/
4200
4201 void
4202 syms_of_frame (void)
4203 {
4204 DEFSYM (Qframep, "framep");
4205 DEFSYM (Qframe_live_p, "frame-live-p");
4206 DEFSYM (Qexplicit_name, "explicit-name");
4207 DEFSYM (Qheight, "height");
4208 DEFSYM (Qicon, "icon");
4209 DEFSYM (Qminibuffer, "minibuffer");
4210 DEFSYM (Qmodeline, "modeline");
4211 DEFSYM (Qonly, "only");
4212 DEFSYM (Qwidth, "width");
4213 DEFSYM (Qgeometry, "geometry");
4214 DEFSYM (Qicon_left, "icon-left");
4215 DEFSYM (Qicon_top, "icon-top");
4216 DEFSYM (Qtooltip, "tooltip");
4217 DEFSYM (Qleft, "left");
4218 DEFSYM (Qright, "right");
4219 DEFSYM (Quser_position, "user-position");
4220 DEFSYM (Quser_size, "user-size");
4221 DEFSYM (Qwindow_id, "window-id");
4222 #ifdef HAVE_X_WINDOWS
4223 DEFSYM (Qouter_window_id, "outer-window-id");
4224 #endif
4225 DEFSYM (Qparent_id, "parent-id");
4226 DEFSYM (Qx, "x");
4227 DEFSYM (Qw32, "w32");
4228 DEFSYM (Qpc, "pc");
4229 DEFSYM (Qmac, "mac");
4230 DEFSYM (Qns, "ns");
4231 DEFSYM (Qvisible, "visible");
4232 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4233 DEFSYM (Qbuffer_list, "buffer-list");
4234 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4235 DEFSYM (Qdisplay_type, "display-type");
4236 DEFSYM (Qbackground_mode, "background-mode");
4237 DEFSYM (Qnoelisp, "noelisp");
4238 DEFSYM (Qtty_color_mode, "tty-color-mode");
4239 DEFSYM (Qtty, "tty");
4240 DEFSYM (Qtty_type, "tty-type");
4241
4242 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4243
4244 DEFSYM (Qfullwidth, "fullwidth");
4245 DEFSYM (Qfullheight, "fullheight");
4246 DEFSYM (Qfullboth, "fullboth");
4247 DEFSYM (Qmaximized, "maximized");
4248 DEFSYM (Qx_resource_name, "x-resource-name");
4249 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4250
4251 DEFSYM (Qterminal, "terminal");
4252 DEFSYM (Qterminal_live_p, "terminal-live-p");
4253
4254 #ifdef HAVE_NS
4255 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4256 #endif
4257
4258 {
4259 int i;
4260
4261 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4262 {
4263 Lisp_Object v = intern_c_string (frame_parms[i].name);
4264 if (frame_parms[i].variable)
4265 {
4266 *frame_parms[i].variable = v;
4267 staticpro (frame_parms[i].variable);
4268 }
4269 Fput (v, Qx_frame_parameter, make_number (i));
4270 }
4271 }
4272
4273 #ifdef HAVE_WINDOW_SYSTEM
4274 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4275 doc: /* The name Emacs uses to look up X resources.
4276 `x-get-resource' uses this as the first component of the instance name
4277 when requesting resource values.
4278 Emacs initially sets `x-resource-name' to the name under which Emacs
4279 was invoked, or to the value specified with the `-name' or `-rn'
4280 switches, if present.
4281
4282 It may be useful to bind this variable locally around a call
4283 to `x-get-resource'. See also the variable `x-resource-class'. */);
4284 Vx_resource_name = Qnil;
4285
4286 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4287 doc: /* The class Emacs uses to look up X resources.
4288 `x-get-resource' uses this as the first component of the instance class
4289 when requesting resource values.
4290
4291 Emacs initially sets `x-resource-class' to "Emacs".
4292
4293 Setting this variable permanently is not a reasonable thing to do,
4294 but binding this variable locally around a call to `x-get-resource'
4295 is a reasonable practice. See also the variable `x-resource-name'. */);
4296 Vx_resource_class = build_string (EMACS_CLASS);
4297
4298 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4299 doc: /* The lower limit of the frame opacity (alpha transparency).
4300 The value should range from 0 (invisible) to 100 (completely opaque).
4301 You can also use a floating number between 0.0 and 1.0.
4302 The default is 20. */);
4303 Vframe_alpha_lower_limit = make_number (20);
4304 #endif
4305
4306 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4307 doc: /* Alist of default values for frame creation.
4308 These may be set in your init file, like this:
4309 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4310 These override values given in window system configuration data,
4311 including X Windows' defaults database.
4312 For values specific to the first Emacs frame, see `initial-frame-alist'.
4313 For window-system specific values, see `window-system-default-frame-alist'.
4314 For values specific to the separate minibuffer frame, see
4315 `minibuffer-frame-alist'.
4316 The `menu-bar-lines' element of the list controls whether new frames
4317 have menu bars; `menu-bar-mode' works by altering this element.
4318 Setting this variable does not affect existing frames, only new ones. */);
4319 Vdefault_frame_alist = Qnil;
4320
4321 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4322 doc: /* Default position of scroll bars on this window-system. */);
4323 #ifdef HAVE_WINDOW_SYSTEM
4324 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4325 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4326 default. */
4327 Vdefault_frame_scroll_bars = Qright;
4328 #else
4329 Vdefault_frame_scroll_bars = Qleft;
4330 #endif
4331 #else
4332 Vdefault_frame_scroll_bars = Qnil;
4333 #endif
4334
4335 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4336 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4337
4338 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4339 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4340 `mouse-position' calls this function, passing its usual return value as
4341 argument, and returns whatever this function returns.
4342 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4343 which need to do mouse handling at the Lisp level. */);
4344 Vmouse_position_function = Qnil;
4345
4346 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4347 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4348 If the value is an integer, highlighting is only shown after moving the
4349 mouse, while keyboard input turns off the highlight even when the mouse
4350 is over the clickable text. However, the mouse shape still indicates
4351 when the mouse is over clickable text. */);
4352 Vmouse_highlight = Qt;
4353
4354 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4355 doc: /* If non-nil, make pointer invisible while typing.
4356 The pointer becomes visible again when the mouse is moved. */);
4357 Vmake_pointer_invisible = Qt;
4358
4359 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4360 doc: /* Functions to be run before deleting a frame.
4361 The functions are run with one arg, the frame to be deleted.
4362 See `delete-frame'.
4363
4364 Note that functions in this list may be called just before the frame is
4365 actually deleted, or some time later (or even both when an earlier function
4366 in `delete-frame-functions' (indirectly) calls `delete-frame'
4367 recursively). */);
4368 Vdelete_frame_functions = Qnil;
4369 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4370
4371 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4372 doc: /* Non-nil if Menu-Bar mode is enabled.
4373 See the command `menu-bar-mode' for a description of this minor mode.
4374 Setting this variable directly does not take effect;
4375 either customize it (see the info node `Easy Customization')
4376 or call the function `menu-bar-mode'. */);
4377 Vmenu_bar_mode = Qt;
4378
4379 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4380 doc: /* Non-nil if Tool-Bar mode is enabled.
4381 See the command `tool-bar-mode' for a description of this minor mode.
4382 Setting this variable directly does not take effect;
4383 either customize it (see the info node `Easy Customization')
4384 or call the function `tool-bar-mode'. */);
4385 #ifdef HAVE_WINDOW_SYSTEM
4386 Vtool_bar_mode = Qt;
4387 #else
4388 Vtool_bar_mode = Qnil;
4389 #endif
4390
4391 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4392 doc: /* Minibufferless frames use this frame's minibuffer.
4393
4394 Emacs cannot create minibufferless frames unless this is set to an
4395 appropriate surrogate.
4396
4397 Emacs consults this variable only when creating minibufferless
4398 frames; once the frame is created, it sticks with its assigned
4399 minibuffer, no matter what this variable is set to. This means that
4400 this variable doesn't necessarily say anything meaningful about the
4401 current set of frames, or where the minibuffer is currently being
4402 displayed.
4403
4404 This variable is local to the current terminal and cannot be buffer-local. */);
4405
4406 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4407 doc: /* Non-nil if window system changes focus when you move the mouse.
4408 You should set this variable to tell Emacs how your window manager
4409 handles focus, since there is no way in general for Emacs to find out
4410 automatically. See also `mouse-autoselect-window'. */);
4411 focus_follows_mouse = 0;
4412
4413 staticpro (&Vframe_list);
4414
4415 defsubr (&Sframep);
4416 defsubr (&Sframe_live_p);
4417 defsubr (&Swindow_system);
4418 defsubr (&Smake_terminal_frame);
4419 defsubr (&Shandle_switch_frame);
4420 defsubr (&Sselect_frame);
4421 defsubr (&Sselected_frame);
4422 defsubr (&Sframe_list);
4423 defsubr (&Snext_frame);
4424 defsubr (&Sprevious_frame);
4425 defsubr (&Sdelete_frame);
4426 defsubr (&Smouse_position);
4427 defsubr (&Smouse_pixel_position);
4428 defsubr (&Sset_mouse_position);
4429 defsubr (&Sset_mouse_pixel_position);
4430 #if 0
4431 defsubr (&Sframe_configuration);
4432 defsubr (&Srestore_frame_configuration);
4433 #endif
4434 defsubr (&Smake_frame_visible);
4435 defsubr (&Smake_frame_invisible);
4436 defsubr (&Siconify_frame);
4437 defsubr (&Sframe_visible_p);
4438 defsubr (&Svisible_frame_list);
4439 defsubr (&Sraise_frame);
4440 defsubr (&Slower_frame);
4441 defsubr (&Sredirect_frame_focus);
4442 defsubr (&Sframe_focus);
4443 defsubr (&Sframe_parameters);
4444 defsubr (&Sframe_parameter);
4445 defsubr (&Smodify_frame_parameters);
4446 defsubr (&Sframe_char_height);
4447 defsubr (&Sframe_char_width);
4448 defsubr (&Sframe_pixel_height);
4449 defsubr (&Sframe_pixel_width);
4450 defsubr (&Stool_bar_pixel_width);
4451 defsubr (&Sset_frame_height);
4452 defsubr (&Sset_frame_width);
4453 defsubr (&Sset_frame_size);
4454 defsubr (&Sset_frame_position);
4455 defsubr (&Sframe_pointer_visible_p);
4456
4457 #ifdef HAVE_WINDOW_SYSTEM
4458 defsubr (&Sx_get_resource);
4459 defsubr (&Sx_parse_geometry);
4460 #endif
4461
4462 }