]> code.delx.au - gnu-emacs/blob - src/frame.c
* frame.c (get_frame_param): Define only if HAVE_WINDOW_SYSTEM.
[gnu-emacs] / 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 = 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 = 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 #ifdef HAVE_WINDOW_SYSTEM
1936 #if !HAVE_NS
1937 static
1938 #endif
1939 Lisp_Object
1940 get_frame_param (register struct frame *frame, Lisp_Object prop)
1941 {
1942 register Lisp_Object tem;
1943
1944 tem = Fassq (prop, frame->param_alist);
1945 if (EQ (tem, Qnil))
1946 return tem;
1947 return Fcdr (tem);
1948 }
1949 #endif
1950
1951 /* Return the buffer-predicate of the selected frame. */
1952
1953 Lisp_Object
1954 frame_buffer_predicate (Lisp_Object frame)
1955 {
1956 return XFRAME (frame)->buffer_predicate;
1957 }
1958
1959 /* Return the buffer-list of the selected frame. */
1960
1961 static Lisp_Object
1962 frame_buffer_list (Lisp_Object frame)
1963 {
1964 return XFRAME (frame)->buffer_list;
1965 }
1966
1967 /* Discard BUFFER from the buffer-list and buried-buffer-list of each frame. */
1968
1969 void
1970 frames_discard_buffer (Lisp_Object buffer)
1971 {
1972 Lisp_Object frame, tail;
1973
1974 FOR_EACH_FRAME (tail, frame)
1975 {
1976 XFRAME (frame)->buffer_list
1977 = Fdelq (buffer, XFRAME (frame)->buffer_list);
1978 XFRAME (frame)->buried_buffer_list
1979 = Fdelq (buffer, XFRAME (frame)->buried_buffer_list);
1980 }
1981 }
1982
1983 /* Modify the alist in *ALISTPTR to associate PROP with VAL.
1984 If the alist already has an element for PROP, we change it. */
1985
1986 void
1987 store_in_alist (Lisp_Object *alistptr, Lisp_Object prop, Lisp_Object val)
1988 {
1989 register Lisp_Object tem;
1990
1991 tem = Fassq (prop, *alistptr);
1992 if (EQ (tem, Qnil))
1993 *alistptr = Fcons (Fcons (prop, val), *alistptr);
1994 else
1995 Fsetcdr (tem, val);
1996 }
1997
1998 static int
1999 frame_name_fnn_p (char *str, ptrdiff_t len)
2000 {
2001 if (len > 1 && str[0] == 'F' && '0' <= str[1] && str[1] <= '9')
2002 {
2003 char *p = str + 2;
2004 while ('0' <= *p && *p <= '9')
2005 p++;
2006 if (p == str + len)
2007 return 1;
2008 }
2009 return 0;
2010 }
2011
2012 /* Set the name of the terminal frame. Also used by MSDOS frames.
2013 Modeled after x_set_name which is used for WINDOW frames. */
2014
2015 static void
2016 set_term_frame_name (struct frame *f, Lisp_Object name)
2017 {
2018 f->explicit_name = ! NILP (name);
2019
2020 /* If NAME is nil, set the name to F<num>. */
2021 if (NILP (name))
2022 {
2023 char namebuf[sizeof "F" + INT_STRLEN_BOUND (printmax_t)];
2024
2025 /* Check for no change needed in this very common case
2026 before we do any consing. */
2027 if (frame_name_fnn_p (SSDATA (f->name),
2028 SBYTES (f->name)))
2029 return;
2030
2031 tty_frame_count++;
2032 sprintf (namebuf, "F%"pMd, tty_frame_count);
2033 name = build_string (namebuf);
2034 }
2035 else
2036 {
2037 CHECK_STRING (name);
2038
2039 /* Don't change the name if it's already NAME. */
2040 if (! NILP (Fstring_equal (name, f->name)))
2041 return;
2042
2043 /* Don't allow the user to set the frame name to F<num>, so it
2044 doesn't clash with the names we generate for terminal frames. */
2045 if (frame_name_fnn_p (SSDATA (name), SBYTES (name)))
2046 error ("Frame names of the form F<num> are usurped by Emacs");
2047 }
2048
2049 f->name = name;
2050 update_mode_lines = 1;
2051 }
2052
2053 void
2054 store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val)
2055 {
2056 register Lisp_Object old_alist_elt;
2057
2058 /* The buffer-list parameters are stored in a special place and not
2059 in the alist. All buffers must be live. */
2060 if (EQ (prop, Qbuffer_list))
2061 {
2062 Lisp_Object list = Qnil;
2063 for (; CONSP (val); val = XCDR (val))
2064 if (!NILP (Fbuffer_live_p (XCAR (val))))
2065 list = Fcons (XCAR (val), list);
2066 f->buffer_list = Fnreverse (list);
2067 return;
2068 }
2069 if (EQ (prop, Qburied_buffer_list))
2070 {
2071 Lisp_Object list = Qnil;
2072 for (; CONSP (val); val = XCDR (val))
2073 if (!NILP (Fbuffer_live_p (XCAR (val))))
2074 list = Fcons (XCAR (val), list);
2075 f->buried_buffer_list = Fnreverse (list);
2076 return;
2077 }
2078
2079 /* If PROP is a symbol which is supposed to have frame-local values,
2080 and it is set up based on this frame, switch to the global
2081 binding. That way, we can create or alter the frame-local binding
2082 without messing up the symbol's status. */
2083 if (SYMBOLP (prop))
2084 {
2085 struct Lisp_Symbol *sym = XSYMBOL (prop);
2086 start:
2087 switch (sym->redirect)
2088 {
2089 case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start;
2090 case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break;
2091 case SYMBOL_LOCALIZED:
2092 { struct Lisp_Buffer_Local_Value *blv = sym->val.blv;
2093 if (blv->frame_local && BLV_FOUND (blv) && XFRAME (blv->where) == f)
2094 swap_in_global_binding (sym);
2095 break;
2096 }
2097 default: abort ();
2098 }
2099 }
2100
2101 /* The tty color needed to be set before the frame's parameter
2102 alist was updated with the new value. This is not true any more,
2103 but we still do this test early on. */
2104 if (FRAME_TERMCAP_P (f) && EQ (prop, Qtty_color_mode)
2105 && f == FRAME_TTY (f)->previous_frame)
2106 /* Force redisplay of this tty. */
2107 FRAME_TTY (f)->previous_frame = NULL;
2108
2109 /* Update the frame parameter alist. */
2110 old_alist_elt = Fassq (prop, f->param_alist);
2111 if (EQ (old_alist_elt, Qnil))
2112 f->param_alist = Fcons (Fcons (prop, val), f->param_alist);
2113 else
2114 Fsetcdr (old_alist_elt, val);
2115
2116 /* Update some other special parameters in their special places
2117 in addition to the alist. */
2118
2119 if (EQ (prop, Qbuffer_predicate))
2120 f->buffer_predicate = val;
2121
2122 if (! FRAME_WINDOW_P (f))
2123 {
2124 if (EQ (prop, Qmenu_bar_lines))
2125 set_menu_bar_lines (f, val, make_number (FRAME_MENU_BAR_LINES (f)));
2126 else if (EQ (prop, Qname))
2127 set_term_frame_name (f, val);
2128 }
2129
2130 if (EQ (prop, Qminibuffer) && WINDOWP (val))
2131 {
2132 if (! MINI_WINDOW_P (XWINDOW (val)))
2133 error ("Surrogate minibuffer windows must be minibuffer windows");
2134
2135 if ((FRAME_HAS_MINIBUF_P (f) || FRAME_MINIBUF_ONLY_P (f))
2136 && !EQ (val, f->minibuffer_window))
2137 error ("Can't change the surrogate minibuffer of a frame with its own minibuffer");
2138
2139 /* Install the chosen minibuffer window, with proper buffer. */
2140 f->minibuffer_window = val;
2141 }
2142 }
2143
2144 DEFUN ("frame-parameters", Fframe_parameters, Sframe_parameters, 0, 1, 0,
2145 doc: /* Return the parameters-alist of frame FRAME.
2146 It is a list of elements of the form (PARM . VALUE), where PARM is a symbol.
2147 The meaningful PARMs depend on the kind of frame.
2148 If FRAME is omitted, return information on the currently selected frame. */)
2149 (Lisp_Object frame)
2150 {
2151 Lisp_Object alist;
2152 FRAME_PTR f;
2153 int height, width;
2154 struct gcpro gcpro1;
2155
2156 if (NILP (frame))
2157 frame = selected_frame;
2158
2159 CHECK_FRAME (frame);
2160 f = XFRAME (frame);
2161
2162 if (!FRAME_LIVE_P (f))
2163 return Qnil;
2164
2165 alist = Fcopy_alist (f->param_alist);
2166 GCPRO1 (alist);
2167
2168 if (!FRAME_WINDOW_P (f))
2169 {
2170 int fg = FRAME_FOREGROUND_PIXEL (f);
2171 int bg = FRAME_BACKGROUND_PIXEL (f);
2172 Lisp_Object elt;
2173
2174 /* If the frame's parameter alist says the colors are
2175 unspecified and reversed, take the frame's background pixel
2176 for foreground and vice versa. */
2177 elt = Fassq (Qforeground_color, alist);
2178 if (CONSP (elt) && STRINGP (XCDR (elt)))
2179 {
2180 if (strncmp (SSDATA (XCDR (elt)),
2181 unspecified_bg,
2182 SCHARS (XCDR (elt))) == 0)
2183 store_in_alist (&alist, Qforeground_color, tty_color_name (f, bg));
2184 else if (strncmp (SSDATA (XCDR (elt)),
2185 unspecified_fg,
2186 SCHARS (XCDR (elt))) == 0)
2187 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2188 }
2189 else
2190 store_in_alist (&alist, Qforeground_color, tty_color_name (f, fg));
2191 elt = Fassq (Qbackground_color, alist);
2192 if (CONSP (elt) && STRINGP (XCDR (elt)))
2193 {
2194 if (strncmp (SSDATA (XCDR (elt)),
2195 unspecified_fg,
2196 SCHARS (XCDR (elt))) == 0)
2197 store_in_alist (&alist, Qbackground_color, tty_color_name (f, fg));
2198 else if (strncmp (SSDATA (XCDR (elt)),
2199 unspecified_bg,
2200 SCHARS (XCDR (elt))) == 0)
2201 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2202 }
2203 else
2204 store_in_alist (&alist, Qbackground_color, tty_color_name (f, bg));
2205 store_in_alist (&alist, intern ("font"),
2206 build_string (FRAME_MSDOS_P (f)
2207 ? "ms-dos"
2208 : FRAME_W32_P (f) ? "w32term"
2209 :"tty"));
2210 }
2211 store_in_alist (&alist, Qname, f->name);
2212 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2213 store_in_alist (&alist, Qheight, make_number (height));
2214 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2215 store_in_alist (&alist, Qwidth, make_number (width));
2216 store_in_alist (&alist, Qmodeline, (FRAME_WANTS_MODELINE_P (f) ? Qt : Qnil));
2217 store_in_alist (&alist, Qminibuffer,
2218 (! FRAME_HAS_MINIBUF_P (f) ? Qnil
2219 : FRAME_MINIBUF_ONLY_P (f) ? Qonly
2220 : FRAME_MINIBUF_WINDOW (f)));
2221 store_in_alist (&alist, Qunsplittable, (FRAME_NO_SPLIT_P (f) ? Qt : Qnil));
2222 store_in_alist (&alist, Qbuffer_list, frame_buffer_list (frame));
2223 store_in_alist (&alist, Qburied_buffer_list, XFRAME (frame)->buried_buffer_list);
2224
2225 /* I think this should be done with a hook. */
2226 #ifdef HAVE_WINDOW_SYSTEM
2227 if (FRAME_WINDOW_P (f))
2228 x_report_frame_params (f, &alist);
2229 else
2230 #endif
2231 {
2232 /* This ought to be correct in f->param_alist for an X frame. */
2233 Lisp_Object lines;
2234 XSETFASTINT (lines, FRAME_MENU_BAR_LINES (f));
2235 store_in_alist (&alist, Qmenu_bar_lines, lines);
2236 }
2237
2238 UNGCPRO;
2239 return alist;
2240 }
2241
2242
2243 DEFUN ("frame-parameter", Fframe_parameter, Sframe_parameter, 2, 2, 0,
2244 doc: /* Return FRAME's value for parameter PARAMETER.
2245 If FRAME is nil, describe the currently selected frame. */)
2246 (Lisp_Object frame, Lisp_Object parameter)
2247 {
2248 struct frame *f;
2249 Lisp_Object value;
2250
2251 if (NILP (frame))
2252 frame = selected_frame;
2253 else
2254 CHECK_FRAME (frame);
2255 CHECK_SYMBOL (parameter);
2256
2257 f = XFRAME (frame);
2258 value = Qnil;
2259
2260 if (FRAME_LIVE_P (f))
2261 {
2262 /* Avoid consing in frequent cases. */
2263 if (EQ (parameter, Qname))
2264 value = f->name;
2265 #ifdef HAVE_X_WINDOWS
2266 else if (EQ (parameter, Qdisplay) && FRAME_X_P (f))
2267 value = XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element);
2268 #endif /* HAVE_X_WINDOWS */
2269 else if (EQ (parameter, Qbackground_color)
2270 || EQ (parameter, Qforeground_color))
2271 {
2272 value = Fassq (parameter, f->param_alist);
2273 if (CONSP (value))
2274 {
2275 value = XCDR (value);
2276 /* Fframe_parameters puts the actual fg/bg color names,
2277 even if f->param_alist says otherwise. This is
2278 important when param_alist's notion of colors is
2279 "unspecified". We need to do the same here. */
2280 if (STRINGP (value) && !FRAME_WINDOW_P (f))
2281 {
2282 const char *color_name;
2283 ptrdiff_t csz;
2284
2285 if (EQ (parameter, Qbackground_color))
2286 {
2287 color_name = SSDATA (value);
2288 csz = SCHARS (value);
2289 if (strncmp (color_name, unspecified_bg, csz) == 0)
2290 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2291 else if (strncmp (color_name, unspecified_fg, csz) == 0)
2292 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2293 }
2294 else if (EQ (parameter, Qforeground_color))
2295 {
2296 color_name = SSDATA (value);
2297 csz = SCHARS (value);
2298 if (strncmp (color_name, unspecified_fg, csz) == 0)
2299 value = tty_color_name (f, FRAME_FOREGROUND_PIXEL (f));
2300 else if (strncmp (color_name, unspecified_bg, csz) == 0)
2301 value = tty_color_name (f, FRAME_BACKGROUND_PIXEL (f));
2302 }
2303 }
2304 }
2305 else
2306 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2307 }
2308 else if (EQ (parameter, Qdisplay_type)
2309 || EQ (parameter, Qbackground_mode))
2310 value = Fcdr (Fassq (parameter, f->param_alist));
2311 else
2312 /* FIXME: Avoid this code path at all (as well as code duplication)
2313 by sharing more code with Fframe_parameters. */
2314 value = Fcdr (Fassq (parameter, Fframe_parameters (frame)));
2315 }
2316
2317 return value;
2318 }
2319
2320
2321 DEFUN ("modify-frame-parameters", Fmodify_frame_parameters,
2322 Smodify_frame_parameters, 2, 2, 0,
2323 doc: /* Modify the parameters of frame FRAME according to ALIST.
2324 If FRAME is nil, it defaults to the selected frame.
2325 ALIST is an alist of parameters to change and their new values.
2326 Each element of ALIST has the form (PARM . VALUE), where PARM is a symbol.
2327 The meaningful PARMs depend on the kind of frame.
2328 Undefined PARMs are ignored, but stored in the frame's parameter list
2329 so that `frame-parameters' will return them.
2330
2331 The value of frame parameter FOO can also be accessed
2332 as a frame-local binding for the variable FOO, if you have
2333 enabled such bindings for that variable with `make-variable-frame-local'.
2334 Note that this functionality is obsolete as of Emacs 22.2, and its
2335 use is not recommended. Explicitly check for a frame-parameter instead. */)
2336 (Lisp_Object frame, Lisp_Object alist)
2337 {
2338 FRAME_PTR f;
2339 register Lisp_Object tail, prop, val;
2340
2341 if (EQ (frame, Qnil))
2342 frame = selected_frame;
2343 CHECK_LIVE_FRAME (frame);
2344 f = XFRAME (frame);
2345
2346 /* I think this should be done with a hook. */
2347 #ifdef HAVE_WINDOW_SYSTEM
2348 if (FRAME_WINDOW_P (f))
2349 x_set_frame_parameters (f, alist);
2350 else
2351 #endif
2352 #ifdef MSDOS
2353 if (FRAME_MSDOS_P (f))
2354 IT_set_frame_parameters (f, alist);
2355 else
2356 #endif
2357
2358 {
2359 EMACS_INT length = XFASTINT (Flength (alist));
2360 ptrdiff_t i;
2361 Lisp_Object *parms;
2362 Lisp_Object *values;
2363 USE_SAFE_ALLOCA;
2364 SAFE_ALLOCA_LISP (parms, 2 * length);
2365 values = parms + length;
2366
2367 /* Extract parm names and values into those vectors. */
2368
2369 i = 0;
2370 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2371 {
2372 Lisp_Object elt;
2373
2374 elt = XCAR (tail);
2375 parms[i] = Fcar (elt);
2376 values[i] = Fcdr (elt);
2377 i++;
2378 }
2379
2380 /* Now process them in reverse of specified order. */
2381 while (--i >= 0)
2382 {
2383 prop = parms[i];
2384 val = values[i];
2385 store_frame_param (f, prop, val);
2386
2387 if (EQ (prop, Qforeground_color)
2388 || EQ (prop, Qbackground_color))
2389 update_face_from_frame_parameter (f, prop, val);
2390 }
2391
2392 SAFE_FREE ();
2393 }
2394 return Qnil;
2395 }
2396 \f
2397 DEFUN ("frame-char-height", Fframe_char_height, Sframe_char_height,
2398 0, 1, 0,
2399 doc: /* Height in pixels of a line in the font in frame FRAME.
2400 If FRAME is omitted, the selected frame is used.
2401 For a terminal frame, the value is always 1. */)
2402 (Lisp_Object frame)
2403 {
2404 struct frame *f;
2405
2406 if (NILP (frame))
2407 frame = selected_frame;
2408 CHECK_FRAME (frame);
2409 f = XFRAME (frame);
2410
2411 #ifdef HAVE_WINDOW_SYSTEM
2412 if (FRAME_WINDOW_P (f))
2413 return make_number (x_char_height (f));
2414 else
2415 #endif
2416 return make_number (1);
2417 }
2418
2419
2420 DEFUN ("frame-char-width", Fframe_char_width, Sframe_char_width,
2421 0, 1, 0,
2422 doc: /* Width in pixels of characters in the font in frame FRAME.
2423 If FRAME is omitted, the selected frame is used.
2424 On a graphical screen, the width is the standard width of the default font.
2425 For a terminal screen, the value is always 1. */)
2426 (Lisp_Object frame)
2427 {
2428 struct frame *f;
2429
2430 if (NILP (frame))
2431 frame = selected_frame;
2432 CHECK_FRAME (frame);
2433 f = XFRAME (frame);
2434
2435 #ifdef HAVE_WINDOW_SYSTEM
2436 if (FRAME_WINDOW_P (f))
2437 return make_number (x_char_width (f));
2438 else
2439 #endif
2440 return make_number (1);
2441 }
2442
2443 DEFUN ("frame-pixel-height", Fframe_pixel_height,
2444 Sframe_pixel_height, 0, 1, 0,
2445 doc: /* Return a FRAME's height in pixels.
2446 If FRAME is omitted, the selected frame is used. The exact value
2447 of the result depends on the window-system and toolkit in use:
2448
2449 In the Gtk+ version of Emacs, it includes only any window (including
2450 the minibuffer or echo area), mode line, and header line. It does not
2451 include the tool bar or menu bar.
2452
2453 With the Motif or Lucid toolkits, it also includes the tool bar (but
2454 not the menu bar).
2455
2456 In a graphical version with no toolkit, it includes both the tool bar
2457 and menu bar.
2458
2459 For a text terminal, it includes the menu bar. In this case, the
2460 result is really in characters rather than pixels (i.e., is identical
2461 to `frame-height'). */)
2462 (Lisp_Object frame)
2463 {
2464 struct frame *f;
2465
2466 if (NILP (frame))
2467 frame = selected_frame;
2468 CHECK_FRAME (frame);
2469 f = XFRAME (frame);
2470
2471 #ifdef HAVE_WINDOW_SYSTEM
2472 if (FRAME_WINDOW_P (f))
2473 return make_number (x_pixel_height (f));
2474 else
2475 #endif
2476 return make_number (FRAME_LINES (f));
2477 }
2478
2479 DEFUN ("frame-pixel-width", Fframe_pixel_width,
2480 Sframe_pixel_width, 0, 1, 0,
2481 doc: /* Return FRAME's width in pixels.
2482 For a terminal frame, the result really gives the width in characters.
2483 If FRAME is omitted, the selected frame is used. */)
2484 (Lisp_Object frame)
2485 {
2486 struct frame *f;
2487
2488 if (NILP (frame))
2489 frame = selected_frame;
2490 CHECK_FRAME (frame);
2491 f = XFRAME (frame);
2492
2493 #ifdef HAVE_WINDOW_SYSTEM
2494 if (FRAME_WINDOW_P (f))
2495 return make_number (x_pixel_width (f));
2496 else
2497 #endif
2498 return make_number (FRAME_COLS (f));
2499 }
2500
2501 DEFUN ("tool-bar-pixel-width", Ftool_bar_pixel_width,
2502 Stool_bar_pixel_width, 0, 1, 0,
2503 doc: /* Return width in pixels of FRAME's tool bar.
2504 The result is greater than zero only when the tool bar is on the left
2505 or right side of FRAME. If FRAME is omitted, the selected frame is
2506 used. */)
2507 (Lisp_Object frame)
2508 {
2509 if (NILP (frame))
2510 frame = selected_frame;
2511 CHECK_FRAME (frame);
2512
2513 #ifdef FRAME_TOOLBAR_WIDTH
2514 if (FRAME_WINDOW_P (XFRAME (frame)))
2515 return make_number (FRAME_TOOLBAR_WIDTH (XFRAME (frame)));
2516 #endif
2517 return make_number (0);
2518 }
2519 \f
2520 DEFUN ("set-frame-height", Fset_frame_height, Sset_frame_height, 2, 3, 0,
2521 doc: /* Specify that the frame FRAME has LINES lines.
2522 Optional third arg non-nil means that redisplay should use LINES lines
2523 but that the idea of the actual height of the frame should not be changed. */)
2524 (Lisp_Object frame, Lisp_Object lines, Lisp_Object pretend)
2525 {
2526 register struct frame *f;
2527
2528 CHECK_TYPE_RANGED_INTEGER (int, lines);
2529 if (NILP (frame))
2530 frame = selected_frame;
2531 CHECK_LIVE_FRAME (frame);
2532 f = XFRAME (frame);
2533
2534 /* I think this should be done with a hook. */
2535 #ifdef HAVE_WINDOW_SYSTEM
2536 if (FRAME_WINDOW_P (f))
2537 {
2538 if (XINT (lines) != FRAME_LINES (f))
2539 x_set_window_size (f, 1, FRAME_COLS (f), XINT (lines));
2540 do_pending_window_change (0);
2541 }
2542 else
2543 #endif
2544 change_frame_size (f, XINT (lines), 0, !NILP (pretend), 0, 0);
2545 return Qnil;
2546 }
2547
2548 DEFUN ("set-frame-width", Fset_frame_width, Sset_frame_width, 2, 3, 0,
2549 doc: /* Specify that the frame FRAME has COLS columns.
2550 Optional third arg non-nil means that redisplay should use COLS columns
2551 but that the idea of the actual width of the frame should not be changed. */)
2552 (Lisp_Object frame, Lisp_Object cols, Lisp_Object pretend)
2553 {
2554 register struct frame *f;
2555 CHECK_TYPE_RANGED_INTEGER (int, cols);
2556 if (NILP (frame))
2557 frame = selected_frame;
2558 CHECK_LIVE_FRAME (frame);
2559 f = XFRAME (frame);
2560
2561 /* I think this should be done with a hook. */
2562 #ifdef HAVE_WINDOW_SYSTEM
2563 if (FRAME_WINDOW_P (f))
2564 {
2565 if (XINT (cols) != FRAME_COLS (f))
2566 x_set_window_size (f, 1, XINT (cols), FRAME_LINES (f));
2567 do_pending_window_change (0);
2568 }
2569 else
2570 #endif
2571 change_frame_size (f, 0, XINT (cols), !NILP (pretend), 0, 0);
2572 return Qnil;
2573 }
2574
2575 DEFUN ("set-frame-size", Fset_frame_size, Sset_frame_size, 3, 3, 0,
2576 doc: /* Sets size of FRAME to COLS by ROWS, measured in characters. */)
2577 (Lisp_Object frame, Lisp_Object cols, Lisp_Object rows)
2578 {
2579 register struct frame *f;
2580
2581 CHECK_LIVE_FRAME (frame);
2582 CHECK_TYPE_RANGED_INTEGER (int, cols);
2583 CHECK_TYPE_RANGED_INTEGER (int, rows);
2584 f = XFRAME (frame);
2585
2586 /* I think this should be done with a hook. */
2587 #ifdef HAVE_WINDOW_SYSTEM
2588 if (FRAME_WINDOW_P (f))
2589 {
2590 if (XINT (rows) != FRAME_LINES (f)
2591 || XINT (cols) != FRAME_COLS (f)
2592 || f->new_text_lines || f->new_text_cols)
2593 x_set_window_size (f, 1, XINT (cols), XINT (rows));
2594 do_pending_window_change (0);
2595 }
2596 else
2597 #endif
2598 change_frame_size (f, XINT (rows), XINT (cols), 0, 0, 0);
2599
2600 return Qnil;
2601 }
2602
2603 DEFUN ("set-frame-position", Fset_frame_position,
2604 Sset_frame_position, 3, 3, 0,
2605 doc: /* Sets position of FRAME in pixels to XOFFSET by YOFFSET.
2606 This is actually the position of the upper left corner of the frame.
2607 Negative values for XOFFSET or YOFFSET are interpreted relative to
2608 the rightmost or bottommost possible position (that stays within the screen). */)
2609 (Lisp_Object frame, Lisp_Object xoffset, Lisp_Object yoffset)
2610 {
2611 register struct frame *f;
2612
2613 CHECK_LIVE_FRAME (frame);
2614 CHECK_TYPE_RANGED_INTEGER (int, xoffset);
2615 CHECK_TYPE_RANGED_INTEGER (int, yoffset);
2616 f = XFRAME (frame);
2617
2618 /* I think this should be done with a hook. */
2619 #ifdef HAVE_WINDOW_SYSTEM
2620 if (FRAME_WINDOW_P (f))
2621 x_set_offset (f, XINT (xoffset), XINT (yoffset), 1);
2622 #endif
2623
2624 return Qt;
2625 }
2626
2627 \f
2628 /***********************************************************************
2629 Frame Parameters
2630 ***********************************************************************/
2631
2632 /* Connect the frame-parameter names for X frames
2633 to the ways of passing the parameter values to the window system.
2634
2635 The name of a parameter, as a Lisp symbol,
2636 has an `x-frame-parameter' property which is an integer in Lisp
2637 that is an index in this table. */
2638
2639 struct frame_parm_table {
2640 const char *name;
2641 Lisp_Object *variable;
2642 };
2643
2644 static const struct frame_parm_table frame_parms[] =
2645 {
2646 {"auto-raise", &Qauto_raise},
2647 {"auto-lower", &Qauto_lower},
2648 {"background-color", 0},
2649 {"border-color", &Qborder_color},
2650 {"border-width", &Qborder_width},
2651 {"cursor-color", &Qcursor_color},
2652 {"cursor-type", &Qcursor_type},
2653 {"font", 0},
2654 {"foreground-color", 0},
2655 {"icon-name", &Qicon_name},
2656 {"icon-type", &Qicon_type},
2657 {"internal-border-width", &Qinternal_border_width},
2658 {"menu-bar-lines", &Qmenu_bar_lines},
2659 {"mouse-color", &Qmouse_color},
2660 {"name", &Qname},
2661 {"scroll-bar-width", &Qscroll_bar_width},
2662 {"title", &Qtitle},
2663 {"unsplittable", &Qunsplittable},
2664 {"vertical-scroll-bars", &Qvertical_scroll_bars},
2665 {"visibility", &Qvisibility},
2666 {"tool-bar-lines", &Qtool_bar_lines},
2667 {"scroll-bar-foreground", &Qscroll_bar_foreground},
2668 {"scroll-bar-background", &Qscroll_bar_background},
2669 {"screen-gamma", &Qscreen_gamma},
2670 {"line-spacing", &Qline_spacing},
2671 {"left-fringe", &Qleft_fringe},
2672 {"right-fringe", &Qright_fringe},
2673 {"wait-for-wm", &Qwait_for_wm},
2674 {"fullscreen", &Qfullscreen},
2675 {"font-backend", &Qfont_backend},
2676 {"alpha", &Qalpha},
2677 {"sticky", &Qsticky},
2678 {"tool-bar-position", &Qtool_bar_position},
2679 };
2680
2681 #ifdef WINDOWSNT
2682
2683 /* Calculate fullscreen size. Return in *TOP_POS and *LEFT_POS the
2684 wanted positions of the WM window (not Emacs window).
2685 Return in *WIDTH and *HEIGHT the wanted width and height of Emacs
2686 window (FRAME_X_WINDOW).
2687 */
2688
2689 void
2690 x_fullscreen_adjust (struct frame *f, int *width, int *height, int *top_pos, int *left_pos)
2691 {
2692 int newwidth = FRAME_COLS (f);
2693 int newheight = FRAME_LINES (f);
2694 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
2695
2696 *top_pos = f->top_pos;
2697 *left_pos = f->left_pos;
2698
2699 if (f->want_fullscreen & FULLSCREEN_HEIGHT)
2700 {
2701 int ph;
2702
2703 ph = x_display_pixel_height (dpyinfo);
2704 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2705 ph = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, newheight) - f->y_pixels_diff;
2706 newheight = FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f, ph);
2707 *top_pos = 0;
2708 }
2709
2710 if (f->want_fullscreen & FULLSCREEN_WIDTH)
2711 {
2712 int pw;
2713
2714 pw = x_display_pixel_width (dpyinfo);
2715 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2716 pw = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, newwidth) - f->x_pixels_diff;
2717 newwidth = FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f, pw);
2718 *left_pos = 0;
2719 }
2720
2721 *width = newwidth;
2722 *height = newheight;
2723 }
2724
2725 #endif /* WINDOWSNT */
2726
2727 #ifdef HAVE_WINDOW_SYSTEM
2728
2729 /* Change the parameters of frame F as specified by ALIST.
2730 If a parameter is not specially recognized, do nothing special;
2731 otherwise call the `x_set_...' function for that parameter.
2732 Except for certain geometry properties, always call store_frame_param
2733 to store the new value in the parameter alist. */
2734
2735 void
2736 x_set_frame_parameters (FRAME_PTR f, Lisp_Object alist)
2737 {
2738 Lisp_Object tail;
2739
2740 /* If both of these parameters are present, it's more efficient to
2741 set them both at once. So we wait until we've looked at the
2742 entire list before we set them. */
2743 int width, height;
2744
2745 /* Same here. */
2746 Lisp_Object left, top;
2747
2748 /* Same with these. */
2749 Lisp_Object icon_left, icon_top;
2750
2751 /* Record in these vectors all the parms specified. */
2752 Lisp_Object *parms;
2753 Lisp_Object *values;
2754 ptrdiff_t i, p;
2755 int left_no_change = 0, top_no_change = 0;
2756 int icon_left_no_change = 0, icon_top_no_change = 0;
2757 int size_changed = 0;
2758 struct gcpro gcpro1, gcpro2;
2759
2760 i = 0;
2761 for (tail = alist; CONSP (tail); tail = Fcdr (tail))
2762 i++;
2763
2764 parms = alloca (i * sizeof *parms);
2765 values = alloca (i * sizeof *values);
2766
2767 /* Extract parm names and values into those vectors. */
2768
2769 i = 0;
2770 for (tail = alist; CONSP (tail); tail = XCDR (tail))
2771 {
2772 Lisp_Object elt;
2773
2774 elt = XCAR (tail);
2775 parms[i] = Fcar (elt);
2776 values[i] = Fcdr (elt);
2777 i++;
2778 }
2779 /* TAIL and ALIST are not used again below here. */
2780 alist = tail = Qnil;
2781
2782 GCPRO2 (*parms, *values);
2783 gcpro1.nvars = i;
2784 gcpro2.nvars = i;
2785
2786 /* There is no need to gcpro LEFT, TOP, ICON_LEFT, or ICON_TOP,
2787 because their values appear in VALUES and strings are not valid. */
2788 top = left = Qunbound;
2789 icon_left = icon_top = Qunbound;
2790
2791 /* Provide default values for HEIGHT and WIDTH. */
2792 width = (f->new_text_cols ? f->new_text_cols : FRAME_COLS (f));
2793 height = (f->new_text_lines ? f->new_text_lines : FRAME_LINES (f));
2794
2795 /* Process foreground_color and background_color before anything else.
2796 They are independent of other properties, but other properties (e.g.,
2797 cursor_color) are dependent upon them. */
2798 /* Process default font as well, since fringe widths depends on it. */
2799 for (p = 0; p < i; p++)
2800 {
2801 Lisp_Object prop, val;
2802
2803 prop = parms[p];
2804 val = values[p];
2805 if (EQ (prop, Qforeground_color)
2806 || EQ (prop, Qbackground_color)
2807 || EQ (prop, Qfont))
2808 {
2809 register Lisp_Object param_index, old_value;
2810
2811 old_value = get_frame_param (f, prop);
2812 if (NILP (Fequal (val, old_value)))
2813 {
2814 store_frame_param (f, prop, val);
2815
2816 param_index = Fget (prop, Qx_frame_parameter);
2817 if (NATNUMP (param_index)
2818 && (XFASTINT (param_index)
2819 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2820 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2821 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2822 }
2823 }
2824 }
2825
2826 /* Now process them in reverse of specified order. */
2827 while (i-- != 0)
2828 {
2829 Lisp_Object prop, val;
2830
2831 prop = parms[i];
2832 val = values[i];
2833
2834 if (EQ (prop, Qwidth) && RANGED_INTEGERP (0, val, INT_MAX))
2835 {
2836 size_changed = 1;
2837 width = XFASTINT (val);
2838 }
2839 else if (EQ (prop, Qheight) && RANGED_INTEGERP (0, val, INT_MAX))
2840 {
2841 size_changed = 1;
2842 height = XFASTINT (val);
2843 }
2844 else if (EQ (prop, Qtop))
2845 top = val;
2846 else if (EQ (prop, Qleft))
2847 left = val;
2848 else if (EQ (prop, Qicon_top))
2849 icon_top = val;
2850 else if (EQ (prop, Qicon_left))
2851 icon_left = val;
2852 else if (EQ (prop, Qforeground_color)
2853 || EQ (prop, Qbackground_color)
2854 || EQ (prop, Qfont))
2855 /* Processed above. */
2856 continue;
2857 else
2858 {
2859 register Lisp_Object param_index, old_value;
2860
2861 old_value = get_frame_param (f, prop);
2862
2863 store_frame_param (f, prop, val);
2864
2865 param_index = Fget (prop, Qx_frame_parameter);
2866 if (NATNUMP (param_index)
2867 && (XFASTINT (param_index)
2868 < sizeof (frame_parms)/sizeof (frame_parms[0]))
2869 && FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])
2870 (*(FRAME_RIF (f)->frame_parm_handlers[XINT (param_index)])) (f, val, old_value);
2871 }
2872 }
2873
2874 /* Don't die if just one of these was set. */
2875 if (! TYPE_RANGED_INTEGERP (int, left))
2876 {
2877 left_no_change = 1;
2878 if (f->left_pos < 0)
2879 left = Fcons (Qplus, Fcons (make_number (f->left_pos), Qnil));
2880 else
2881 XSETINT (left, f->left_pos);
2882 }
2883 if (! TYPE_RANGED_INTEGERP (int, top))
2884 {
2885 top_no_change = 1;
2886 if (f->top_pos < 0)
2887 top = Fcons (Qplus, Fcons (make_number (f->top_pos), Qnil));
2888 else
2889 XSETINT (top, f->top_pos);
2890 }
2891
2892 /* If one of the icon positions was not set, preserve or default it. */
2893 if (! TYPE_RANGED_INTEGERP (int, icon_left))
2894 {
2895 icon_left_no_change = 1;
2896 icon_left = Fcdr (Fassq (Qicon_left, f->param_alist));
2897 if (NILP (icon_left))
2898 XSETINT (icon_left, 0);
2899 }
2900 if (! TYPE_RANGED_INTEGERP (int, icon_top))
2901 {
2902 icon_top_no_change = 1;
2903 icon_top = Fcdr (Fassq (Qicon_top, f->param_alist));
2904 if (NILP (icon_top))
2905 XSETINT (icon_top, 0);
2906 }
2907
2908 /* Don't set these parameters unless they've been explicitly
2909 specified. The window might be mapped or resized while we're in
2910 this function, and we don't want to override that unless the lisp
2911 code has asked for it.
2912
2913 Don't set these parameters unless they actually differ from the
2914 window's current parameters; the window may not actually exist
2915 yet. */
2916 {
2917 Lisp_Object frame;
2918
2919 check_frame_size (f, &height, &width);
2920
2921 XSETFRAME (frame, f);
2922
2923 if (size_changed
2924 && (width != FRAME_COLS (f)
2925 || height != FRAME_LINES (f)
2926 || f->new_text_lines || f->new_text_cols))
2927 Fset_frame_size (frame, make_number (width), make_number (height));
2928
2929 if ((!NILP (left) || !NILP (top))
2930 && ! (left_no_change && top_no_change)
2931 && ! (NUMBERP (left) && XINT (left) == f->left_pos
2932 && NUMBERP (top) && XINT (top) == f->top_pos))
2933 {
2934 int leftpos = 0;
2935 int toppos = 0;
2936
2937 /* Record the signs. */
2938 f->size_hint_flags &= ~ (XNegative | YNegative);
2939 if (EQ (left, Qminus))
2940 f->size_hint_flags |= XNegative;
2941 else if (TYPE_RANGED_INTEGERP (int, left))
2942 {
2943 leftpos = XINT (left);
2944 if (leftpos < 0)
2945 f->size_hint_flags |= XNegative;
2946 }
2947 else if (CONSP (left) && EQ (XCAR (left), Qminus)
2948 && CONSP (XCDR (left))
2949 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (left)), INT_MAX))
2950 {
2951 leftpos = - XINT (XCAR (XCDR (left)));
2952 f->size_hint_flags |= XNegative;
2953 }
2954 else if (CONSP (left) && EQ (XCAR (left), Qplus)
2955 && CONSP (XCDR (left))
2956 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (left))))
2957 {
2958 leftpos = XINT (XCAR (XCDR (left)));
2959 }
2960
2961 if (EQ (top, Qminus))
2962 f->size_hint_flags |= YNegative;
2963 else if (TYPE_RANGED_INTEGERP (int, top))
2964 {
2965 toppos = XINT (top);
2966 if (toppos < 0)
2967 f->size_hint_flags |= YNegative;
2968 }
2969 else if (CONSP (top) && EQ (XCAR (top), Qminus)
2970 && CONSP (XCDR (top))
2971 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (top)), INT_MAX))
2972 {
2973 toppos = - XINT (XCAR (XCDR (top)));
2974 f->size_hint_flags |= YNegative;
2975 }
2976 else if (CONSP (top) && EQ (XCAR (top), Qplus)
2977 && CONSP (XCDR (top))
2978 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (top))))
2979 {
2980 toppos = XINT (XCAR (XCDR (top)));
2981 }
2982
2983
2984 /* Store the numeric value of the position. */
2985 f->top_pos = toppos;
2986 f->left_pos = leftpos;
2987
2988 f->win_gravity = NorthWestGravity;
2989
2990 /* Actually set that position, and convert to absolute. */
2991 x_set_offset (f, leftpos, toppos, -1);
2992 }
2993
2994 if ((!NILP (icon_left) || !NILP (icon_top))
2995 && ! (icon_left_no_change && icon_top_no_change))
2996 x_wm_set_icon_position (f, XINT (icon_left), XINT (icon_top));
2997 }
2998
2999 UNGCPRO;
3000 }
3001
3002
3003 /* Insert a description of internally-recorded parameters of frame X
3004 into the parameter alist *ALISTPTR that is to be given to the user.
3005 Only parameters that are specific to the X window system
3006 and whose values are not correctly recorded in the frame's
3007 param_alist need to be considered here. */
3008
3009 void
3010 x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
3011 {
3012 char buf[16];
3013 Lisp_Object tem;
3014 unsigned long w;
3015
3016 /* Represent negative positions (off the top or left screen edge)
3017 in a way that Fmodify_frame_parameters will understand correctly. */
3018 XSETINT (tem, f->left_pos);
3019 if (f->left_pos >= 0)
3020 store_in_alist (alistptr, Qleft, tem);
3021 else
3022 store_in_alist (alistptr, Qleft, Fcons (Qplus, Fcons (tem, Qnil)));
3023
3024 XSETINT (tem, f->top_pos);
3025 if (f->top_pos >= 0)
3026 store_in_alist (alistptr, Qtop, tem);
3027 else
3028 store_in_alist (alistptr, Qtop, Fcons (Qplus, Fcons (tem, Qnil)));
3029
3030 store_in_alist (alistptr, Qborder_width,
3031 make_number (f->border_width));
3032 store_in_alist (alistptr, Qinternal_border_width,
3033 make_number (FRAME_INTERNAL_BORDER_WIDTH (f)));
3034 store_in_alist (alistptr, Qleft_fringe,
3035 make_number (FRAME_LEFT_FRINGE_WIDTH (f)));
3036 store_in_alist (alistptr, Qright_fringe,
3037 make_number (FRAME_RIGHT_FRINGE_WIDTH (f)));
3038 store_in_alist (alistptr, Qscroll_bar_width,
3039 (! FRAME_HAS_VERTICAL_SCROLL_BARS (f)
3040 ? make_number (0)
3041 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f) > 0
3042 ? make_number (FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3043 /* nil means "use default width"
3044 for non-toolkit scroll bar.
3045 ruler-mode.el depends on this. */
3046 : Qnil));
3047 /* FRAME_X_WINDOW is not guaranteed to return an integer. E.g., on
3048 MS-Windows it returns a value whose type is HANDLE, which is
3049 actually a pointer. Explicit casting avoids compiler
3050 warnings. */
3051 w = (unsigned long) FRAME_X_WINDOW (f);
3052 sprintf (buf, "%lu", w);
3053 store_in_alist (alistptr, Qwindow_id,
3054 build_string (buf));
3055 #ifdef HAVE_X_WINDOWS
3056 #ifdef USE_X_TOOLKIT
3057 /* Tooltip frame may not have this widget. */
3058 if (FRAME_X_OUTPUT (f)->widget)
3059 #endif
3060 {
3061 w = (unsigned long) FRAME_OUTER_WINDOW (f);
3062 sprintf (buf, "%lu", w);
3063 }
3064 store_in_alist (alistptr, Qouter_window_id,
3065 build_string (buf));
3066 #endif
3067 store_in_alist (alistptr, Qicon_name, f->icon_name);
3068 FRAME_SAMPLE_VISIBILITY (f);
3069 store_in_alist (alistptr, Qvisibility,
3070 (FRAME_VISIBLE_P (f) ? Qt
3071 : FRAME_ICONIFIED_P (f) ? Qicon : Qnil));
3072 store_in_alist (alistptr, Qdisplay,
3073 XCAR (FRAME_X_DISPLAY_INFO (f)->name_list_element));
3074
3075 if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_X_DISPLAY_INFO (f)->root_window)
3076 tem = Qnil;
3077 else
3078 XSETFASTINT (tem, FRAME_X_OUTPUT (f)->parent_desc);
3079 store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
3080 store_in_alist (alistptr, Qparent_id, tem);
3081 store_in_alist (alistptr, Qtool_bar_position, f->tool_bar_position);
3082 }
3083
3084
3085 /* Change the `fullscreen' frame parameter of frame F. OLD_VALUE is
3086 the previous value of that parameter, NEW_VALUE is the new value. */
3087
3088 void
3089 x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3090 {
3091 if (NILP (new_value))
3092 f->want_fullscreen = FULLSCREEN_NONE;
3093 else if (EQ (new_value, Qfullboth) || EQ (new_value, Qfullscreen))
3094 f->want_fullscreen = FULLSCREEN_BOTH;
3095 else if (EQ (new_value, Qfullwidth))
3096 f->want_fullscreen = FULLSCREEN_WIDTH;
3097 else if (EQ (new_value, Qfullheight))
3098 f->want_fullscreen = FULLSCREEN_HEIGHT;
3099 else if (EQ (new_value, Qmaximized))
3100 f->want_fullscreen = FULLSCREEN_MAXIMIZED;
3101
3102 if (FRAME_TERMINAL (f)->fullscreen_hook != NULL)
3103 FRAME_TERMINAL (f)->fullscreen_hook (f);
3104 }
3105
3106
3107 /* Change the `line-spacing' frame parameter of frame F. OLD_VALUE is
3108 the previous value of that parameter, NEW_VALUE is the new value. */
3109
3110 void
3111 x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3112 {
3113 if (NILP (new_value))
3114 f->extra_line_spacing = 0;
3115 else if (RANGED_INTEGERP (0, new_value, INT_MAX))
3116 f->extra_line_spacing = XFASTINT (new_value);
3117 else
3118 signal_error ("Invalid line-spacing", new_value);
3119 if (FRAME_VISIBLE_P (f))
3120 redraw_frame (f);
3121 }
3122
3123
3124 /* Change the `screen-gamma' frame parameter of frame F. OLD_VALUE is
3125 the previous value of that parameter, NEW_VALUE is the new value. */
3126
3127 void
3128 x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3129 {
3130 Lisp_Object bgcolor;
3131
3132 if (NILP (new_value))
3133 f->gamma = 0;
3134 else if (NUMBERP (new_value) && XFLOATINT (new_value) > 0)
3135 /* The value 0.4545 is the normal viewing gamma. */
3136 f->gamma = 1.0 / (0.4545 * XFLOATINT (new_value));
3137 else
3138 signal_error ("Invalid screen-gamma", new_value);
3139
3140 /* Apply the new gamma value to the frame background. */
3141 bgcolor = Fassq (Qbackground_color, f->param_alist);
3142 if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
3143 {
3144 Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
3145 if (NATNUMP (parm_index)
3146 && (XFASTINT (parm_index)
3147 < sizeof (frame_parms)/sizeof (frame_parms[0]))
3148 && FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3149 (*FRAME_RIF (f)->frame_parm_handlers[XFASTINT (parm_index)])
3150 (f, bgcolor, Qnil);
3151 }
3152
3153 Fclear_face_cache (Qnil);
3154 }
3155
3156
3157 void
3158 x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3159 {
3160 Lisp_Object font_object;
3161 int fontset = -1;
3162 #ifdef HAVE_X_WINDOWS
3163 Lisp_Object font_param = arg;
3164 #endif
3165
3166 /* Set the frame parameter back to the old value because we may
3167 fail to use ARG as the new parameter value. */
3168 store_frame_param (f, Qfont, oldval);
3169
3170 /* ARG is a fontset name, a font name, a cons of fontset name and a
3171 font object, or a font object. In the last case, this function
3172 never fail. */
3173 if (STRINGP (arg))
3174 {
3175 fontset = fs_query_fontset (arg, 0);
3176 if (fontset < 0)
3177 {
3178 font_object = font_open_by_name (f, SSDATA (arg));
3179 if (NILP (font_object))
3180 error ("Font `%s' is not defined", SSDATA (arg));
3181 arg = AREF (font_object, FONT_NAME_INDEX);
3182 }
3183 else if (fontset > 0)
3184 {
3185 Lisp_Object ascii_font = fontset_ascii (fontset);
3186
3187 font_object = font_open_by_name (f, SSDATA (ascii_font));
3188 if (NILP (font_object))
3189 error ("Font `%s' is not defined", SDATA (arg));
3190 arg = AREF (font_object, FONT_NAME_INDEX);
3191 }
3192 else
3193 error ("The default fontset can't be used for a frame font");
3194 }
3195 else if (CONSP (arg) && STRINGP (XCAR (arg)) && FONT_OBJECT_P (XCDR (arg)))
3196 {
3197 /* This is the case that the ASCII font of F's fontset XCAR
3198 (arg) is changed to the font XCDR (arg) by
3199 `set-fontset-font'. */
3200 fontset = fs_query_fontset (XCAR (arg), 0);
3201 if (fontset < 0)
3202 error ("Unknown fontset: %s", SDATA (XCAR (arg)));
3203 font_object = XCDR (arg);
3204 arg = AREF (font_object, FONT_NAME_INDEX);
3205 #ifdef HAVE_X_WINDOWS
3206 font_param = Ffont_get (font_object, QCname);
3207 #endif
3208 }
3209 else if (FONT_OBJECT_P (arg))
3210 {
3211 font_object = arg;
3212 #ifdef HAVE_X_WINDOWS
3213 font_param = Ffont_get (font_object, QCname);
3214 #endif
3215 /* This is to store the XLFD font name in the frame parameter for
3216 backward compatibility. We should store the font-object
3217 itself in the future. */
3218 arg = AREF (font_object, FONT_NAME_INDEX);
3219 fontset = FRAME_FONTSET (f);
3220 /* Check if we can use the current fontset. If not, set FONTSET
3221 to -1 to generate a new fontset from FONT-OBJECT. */
3222 if (fontset >= 0)
3223 {
3224 Lisp_Object ascii_font = fontset_ascii (fontset);
3225 Lisp_Object spec = font_spec_from_name (ascii_font);
3226
3227 if (! font_match_p (spec, font_object))
3228 fontset = -1;
3229 }
3230 }
3231 else
3232 signal_error ("Invalid font", arg);
3233
3234 if (! NILP (Fequal (font_object, oldval)))
3235 return;
3236
3237 x_new_font (f, font_object, fontset);
3238 store_frame_param (f, Qfont, arg);
3239 #ifdef HAVE_X_WINDOWS
3240 store_frame_param (f, Qfont_param, font_param);
3241 #endif
3242 /* Recalculate toolbar height. */
3243 f->n_tool_bar_rows = 0;
3244 /* Ensure we redraw it. */
3245 clear_current_matrices (f);
3246
3247 recompute_basic_faces (f);
3248
3249 do_pending_window_change (0);
3250
3251 /* We used to call face-set-after-frame-default here, but it leads to
3252 recursive calls (since that function can set the `default' face's
3253 font which in turns changes the frame's `font' parameter).
3254 Also I don't know what this call is meant to do, but it seems the
3255 wrong way to do it anyway (it does a lot more work than what seems
3256 reasonable in response to a change to `font'). */
3257 }
3258
3259
3260 void
3261 x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3262 {
3263 if (! NILP (new_value)
3264 && !CONSP (new_value))
3265 {
3266 char *p0, *p1;
3267
3268 CHECK_STRING (new_value);
3269 p0 = p1 = SSDATA (new_value);
3270 new_value = Qnil;
3271 while (*p0)
3272 {
3273 while (*p1 && ! isspace (*p1) && *p1 != ',') p1++;
3274 if (p0 < p1)
3275 new_value = Fcons (Fintern (make_string (p0, p1 - p0), Qnil),
3276 new_value);
3277 if (*p1)
3278 {
3279 int c;
3280
3281 while ((c = *++p1) && isspace (c));
3282 }
3283 p0 = p1;
3284 }
3285 new_value = Fnreverse (new_value);
3286 }
3287
3288 if (! NILP (old_value) && ! NILP (Fequal (old_value, new_value)))
3289 return;
3290
3291 if (FRAME_FONT (f))
3292 free_all_realized_faces (Qnil);
3293
3294 new_value = font_update_drivers (f, NILP (new_value) ? Qt : new_value);
3295 if (NILP (new_value))
3296 {
3297 if (NILP (old_value))
3298 error ("No font backend available");
3299 font_update_drivers (f, old_value);
3300 error ("None of specified font backends are available");
3301 }
3302 store_frame_param (f, Qfont_backend, new_value);
3303
3304 if (FRAME_FONT (f))
3305 {
3306 Lisp_Object frame;
3307
3308 XSETFRAME (frame, f);
3309 x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
3310 ++face_change_count;
3311 ++windows_or_buffers_changed;
3312 }
3313 }
3314
3315
3316 void
3317 x_set_fringe_width (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
3318 {
3319 compute_fringe_widths (f, 1);
3320 #ifdef HAVE_X_WINDOWS
3321 /* Must adjust this so window managers report correct number of columns. */
3322 if (FRAME_X_WINDOW (f) != 0)
3323 x_wm_set_size_hint (f, 0, 0);
3324 #endif
3325 }
3326
3327 void
3328 x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3329 {
3330 CHECK_TYPE_RANGED_INTEGER (int, arg);
3331
3332 if (XINT (arg) == f->border_width)
3333 return;
3334
3335 if (FRAME_X_WINDOW (f) != 0)
3336 error ("Cannot change the border width of a frame");
3337
3338 f->border_width = XINT (arg);
3339 }
3340
3341 void
3342 x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3343 {
3344 int old = FRAME_INTERNAL_BORDER_WIDTH (f);
3345
3346 CHECK_TYPE_RANGED_INTEGER (int, arg);
3347 FRAME_INTERNAL_BORDER_WIDTH (f) = XINT (arg);
3348 if (FRAME_INTERNAL_BORDER_WIDTH (f) < 0)
3349 FRAME_INTERNAL_BORDER_WIDTH (f) = 0;
3350
3351 #ifdef USE_X_TOOLKIT
3352 if (FRAME_X_OUTPUT (f)->edit_widget)
3353 widget_store_internal_border (FRAME_X_OUTPUT (f)->edit_widget);
3354 #endif
3355
3356 if (FRAME_INTERNAL_BORDER_WIDTH (f) == old)
3357 return;
3358
3359 if (FRAME_X_WINDOW (f) != 0)
3360 {
3361 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3362 SET_FRAME_GARBAGED (f);
3363 do_pending_window_change (0);
3364 }
3365 else
3366 SET_FRAME_GARBAGED (f);
3367 }
3368
3369 void
3370 x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
3371 {
3372 Lisp_Object frame;
3373 XSETFRAME (frame, f);
3374
3375 if (NILP (value))
3376 Fmake_frame_invisible (frame, Qt);
3377 else if (EQ (value, Qicon))
3378 Ficonify_frame (frame);
3379 else
3380 Fmake_frame_visible (frame);
3381 }
3382
3383 void
3384 x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3385 {
3386 f->auto_raise = !EQ (Qnil, arg);
3387 }
3388
3389 void
3390 x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3391 {
3392 f->auto_lower = !EQ (Qnil, arg);
3393 }
3394
3395 void
3396 x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3397 {
3398 f->no_split = !NILP (arg);
3399 }
3400
3401 void
3402 x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3403 {
3404 if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
3405 || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
3406 || (NILP (arg) && FRAME_HAS_VERTICAL_SCROLL_BARS (f))
3407 || (!NILP (arg) && ! FRAME_HAS_VERTICAL_SCROLL_BARS (f)))
3408 {
3409 FRAME_VERTICAL_SCROLL_BAR_TYPE (f)
3410 = (NILP (arg)
3411 ? vertical_scroll_bar_none
3412 : EQ (Qleft, arg)
3413 ? vertical_scroll_bar_left
3414 : EQ (Qright, arg)
3415 ? vertical_scroll_bar_right
3416 : EQ (Qleft, Vdefault_frame_scroll_bars)
3417 ? vertical_scroll_bar_left
3418 : EQ (Qright, Vdefault_frame_scroll_bars)
3419 ? vertical_scroll_bar_right
3420 : vertical_scroll_bar_none);
3421
3422 /* We set this parameter before creating the X window for the
3423 frame, so we can get the geometry right from the start.
3424 However, if the window hasn't been created yet, we shouldn't
3425 call x_set_window_size. */
3426 if (FRAME_X_WINDOW (f))
3427 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3428 do_pending_window_change (0);
3429 }
3430 }
3431
3432 void
3433 x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3434 {
3435 int wid = FRAME_COLUMN_WIDTH (f);
3436
3437 if (NILP (arg))
3438 {
3439 x_set_scroll_bar_default_width (f);
3440
3441 if (FRAME_X_WINDOW (f))
3442 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3443 do_pending_window_change (0);
3444 }
3445 else if (RANGED_INTEGERP (1, arg, INT_MAX)
3446 && XFASTINT (arg) != FRAME_CONFIG_SCROLL_BAR_WIDTH (f))
3447 {
3448 if (XFASTINT (arg) <= 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM)
3449 XSETINT (arg, 2 * VERTICAL_SCROLL_BAR_WIDTH_TRIM + 1);
3450
3451 FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFASTINT (arg);
3452 FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFASTINT (arg) + wid-1) / wid;
3453 if (FRAME_X_WINDOW (f))
3454 x_set_window_size (f, 0, FRAME_COLS (f), FRAME_LINES (f));
3455 do_pending_window_change (0);
3456 }
3457
3458 change_frame_size (f, 0, FRAME_COLS (f), 0, 0, 0);
3459 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.hpos = 0;
3460 XWINDOW (FRAME_SELECTED_WINDOW (f))->cursor.x = 0;
3461 }
3462
3463
3464
3465 /* Return non-nil if frame F wants a bitmap icon. */
3466
3467 Lisp_Object
3468 x_icon_type (FRAME_PTR f)
3469 {
3470 Lisp_Object tem;
3471
3472 tem = assq_no_quit (Qicon_type, f->param_alist);
3473 if (CONSP (tem))
3474 return XCDR (tem);
3475 else
3476 return Qnil;
3477 }
3478
3479 void
3480 x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3481 {
3482 double alpha = 1.0;
3483 double newval[2];
3484 int i;
3485 Lisp_Object item;
3486
3487 for (i = 0; i < 2; i++)
3488 {
3489 newval[i] = 1.0;
3490 if (CONSP (arg))
3491 {
3492 item = CAR (arg);
3493 arg = CDR (arg);
3494 }
3495 else
3496 item = arg;
3497
3498 if (NILP (item))
3499 alpha = - 1.0;
3500 else if (FLOATP (item))
3501 {
3502 alpha = XFLOAT_DATA (item);
3503 if (alpha < 0.0 || 1.0 < alpha)
3504 args_out_of_range (make_float (0.0), make_float (1.0));
3505 }
3506 else if (INTEGERP (item))
3507 {
3508 EMACS_INT ialpha = XINT (item);
3509 if (ialpha < 0 || 100 < ialpha)
3510 args_out_of_range (make_number (0), make_number (100));
3511 else
3512 alpha = ialpha / 100.0;
3513 }
3514 else
3515 wrong_type_argument (Qnumberp, item);
3516 newval[i] = alpha;
3517 }
3518
3519 for (i = 0; i < 2; i++)
3520 f->alpha[i] = newval[i];
3521
3522 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
3523 BLOCK_INPUT;
3524 x_set_frame_alpha (f);
3525 UNBLOCK_INPUT;
3526 #endif
3527
3528 return;
3529 }
3530
3531 \f
3532 /* Subroutines of creating an X frame. */
3533
3534 /* Make sure that Vx_resource_name is set to a reasonable value.
3535 Fix it up, or set it to `emacs' if it is too hopeless. */
3536
3537 void
3538 validate_x_resource_name (void)
3539 {
3540 ptrdiff_t len = 0;
3541 /* Number of valid characters in the resource name. */
3542 ptrdiff_t good_count = 0;
3543 /* Number of invalid characters in the resource name. */
3544 ptrdiff_t bad_count = 0;
3545 Lisp_Object new;
3546 ptrdiff_t i;
3547
3548 if (!STRINGP (Vx_resource_class))
3549 Vx_resource_class = build_string (EMACS_CLASS);
3550
3551 if (STRINGP (Vx_resource_name))
3552 {
3553 unsigned char *p = SDATA (Vx_resource_name);
3554
3555 len = SBYTES (Vx_resource_name);
3556
3557 /* Only letters, digits, - and _ are valid in resource names.
3558 Count the valid characters and count the invalid ones. */
3559 for (i = 0; i < len; i++)
3560 {
3561 int c = p[i];
3562 if (! ((c >= 'a' && c <= 'z')
3563 || (c >= 'A' && c <= 'Z')
3564 || (c >= '0' && c <= '9')
3565 || c == '-' || c == '_'))
3566 bad_count++;
3567 else
3568 good_count++;
3569 }
3570 }
3571 else
3572 /* Not a string => completely invalid. */
3573 bad_count = 5, good_count = 0;
3574
3575 /* If name is valid already, return. */
3576 if (bad_count == 0)
3577 return;
3578
3579 /* If name is entirely invalid, or nearly so, or is so implausibly
3580 large that alloca might not work, use `emacs'. */
3581 if (good_count < 2 || MAX_ALLOCA - sizeof ".customization" < len)
3582 {
3583 Vx_resource_name = build_string ("emacs");
3584 return;
3585 }
3586
3587 /* Name is partly valid. Copy it and replace the invalid characters
3588 with underscores. */
3589
3590 Vx_resource_name = new = Fcopy_sequence (Vx_resource_name);
3591
3592 for (i = 0; i < len; i++)
3593 {
3594 int c = SREF (new, i);
3595 if (! ((c >= 'a' && c <= 'z')
3596 || (c >= 'A' && c <= 'Z')
3597 || (c >= '0' && c <= '9')
3598 || c == '-' || c == '_'))
3599 SSET (new, i, '_');
3600 }
3601 }
3602
3603
3604 extern char *x_get_string_resource (XrmDatabase, const char *, const char *);
3605 extern Display_Info *check_x_display_info (Lisp_Object);
3606
3607
3608 /* Get specified attribute from resource database RDB.
3609 See Fx_get_resource below for other parameters. */
3610
3611 static Lisp_Object
3612 xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3613 {
3614 register char *value;
3615 char *name_key;
3616 char *class_key;
3617
3618 CHECK_STRING (attribute);
3619 CHECK_STRING (class);
3620
3621 if (!NILP (component))
3622 CHECK_STRING (component);
3623 if (!NILP (subclass))
3624 CHECK_STRING (subclass);
3625 if (NILP (component) != NILP (subclass))
3626 error ("x-get-resource: must specify both COMPONENT and SUBCLASS or neither");
3627
3628 validate_x_resource_name ();
3629
3630 /* Allocate space for the components, the dots which separate them,
3631 and the final '\0'. Make them big enough for the worst case. */
3632 name_key = alloca (SBYTES (Vx_resource_name)
3633 + (STRINGP (component)
3634 ? SBYTES (component) : 0)
3635 + SBYTES (attribute)
3636 + 3);
3637
3638 class_key = alloca (SBYTES (Vx_resource_class)
3639 + SBYTES (class)
3640 + (STRINGP (subclass)
3641 ? SBYTES (subclass) : 0)
3642 + 3);
3643
3644 /* Start with emacs.FRAMENAME for the name (the specific one)
3645 and with `Emacs' for the class key (the general one). */
3646 strcpy (name_key, SSDATA (Vx_resource_name));
3647 strcpy (class_key, SSDATA (Vx_resource_class));
3648
3649 strcat (class_key, ".");
3650 strcat (class_key, SSDATA (class));
3651
3652 if (!NILP (component))
3653 {
3654 strcat (class_key, ".");
3655 strcat (class_key, SSDATA (subclass));
3656
3657 strcat (name_key, ".");
3658 strcat (name_key, SSDATA (component));
3659 }
3660
3661 strcat (name_key, ".");
3662 strcat (name_key, SSDATA (attribute));
3663
3664 value = x_get_string_resource (rdb, name_key, class_key);
3665
3666 if (value != (char *) 0 && *value)
3667 return build_string (value);
3668 else
3669 return Qnil;
3670 }
3671
3672
3673 DEFUN ("x-get-resource", Fx_get_resource, Sx_get_resource, 2, 4, 0,
3674 doc: /* Return the value of ATTRIBUTE, of class CLASS, from the X defaults database.
3675 This uses `INSTANCE.ATTRIBUTE' as the key and `Emacs.CLASS' as the
3676 class, where INSTANCE is the name under which Emacs was invoked, or
3677 the name specified by the `-name' or `-rn' command-line arguments.
3678
3679 The optional arguments COMPONENT and SUBCLASS add to the key and the
3680 class, respectively. You must specify both of them or neither.
3681 If you specify them, the key is `INSTANCE.COMPONENT.ATTRIBUTE'
3682 and the class is `Emacs.CLASS.SUBCLASS'. */)
3683 (Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3684 {
3685 #ifdef HAVE_X_WINDOWS
3686 check_x ();
3687 #endif
3688
3689 return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
3690 attribute, class, component, subclass);
3691 }
3692
3693 /* Get an X resource, like Fx_get_resource, but for display DPYINFO. */
3694
3695 Lisp_Object
3696 display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
3697 {
3698 return xrdb_get_resource (dpyinfo->xrdb,
3699 attribute, class, component, subclass);
3700 }
3701
3702 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT
3703 /* Used when C code wants a resource value. */
3704 /* Called from oldXMenu/Create.c. */
3705 char *
3706 x_get_resource_string (const char *attribute, const char *class)
3707 {
3708 char *name_key;
3709 char *class_key;
3710 char *result;
3711 struct frame *sf = SELECTED_FRAME ();
3712 ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
3713 USE_SAFE_ALLOCA;
3714
3715 /* Allocate space for the components, the dots which separate them,
3716 and the final '\0'. */
3717 SAFE_ALLOCA (name_key, char *, invocation_namelen + strlen (attribute) + 2);
3718 class_key = alloca ((sizeof (EMACS_CLASS) - 1) + strlen (class) + 2);
3719
3720 esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
3721 sprintf (class_key, "%s.%s", EMACS_CLASS, class);
3722
3723 result = x_get_string_resource (FRAME_X_DISPLAY_INFO (sf)->xrdb,
3724 name_key, class_key);
3725 SAFE_FREE ();
3726 return result;
3727 }
3728 #endif
3729
3730 /* Return the value of parameter PARAM.
3731
3732 First search ALIST, then Vdefault_frame_alist, then the X defaults
3733 database, using ATTRIBUTE as the attribute name and CLASS as its class.
3734
3735 Convert the resource to the type specified by desired_type.
3736
3737 If no default is specified, return Qunbound. If you call
3738 x_get_arg, make sure you deal with Qunbound in a reasonable way,
3739 and don't let it get stored in any Lisp-visible variables! */
3740
3741 Lisp_Object
3742 x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
3743 const char *attribute, const char *class, enum resource_types type)
3744 {
3745 register Lisp_Object tem;
3746
3747 tem = Fassq (param, alist);
3748
3749 if (!NILP (tem))
3750 {
3751 /* If we find this parm in ALIST, clear it out
3752 so that it won't be "left over" at the end. */
3753 Lisp_Object tail;
3754 XSETCAR (tem, Qnil);
3755 /* In case the parameter appears more than once in the alist,
3756 clear it out. */
3757 for (tail = alist; CONSP (tail); tail = XCDR (tail))
3758 if (CONSP (XCAR (tail))
3759 && EQ (XCAR (XCAR (tail)), param))
3760 XSETCAR (XCAR (tail), Qnil);
3761 }
3762 else
3763 tem = Fassq (param, Vdefault_frame_alist);
3764
3765 /* If it wasn't specified in ALIST or the Lisp-level defaults,
3766 look in the X resources. */
3767 if (EQ (tem, Qnil))
3768 {
3769 if (attribute && dpyinfo)
3770 {
3771 tem = display_x_get_resource (dpyinfo,
3772 build_string (attribute),
3773 build_string (class),
3774 Qnil, Qnil);
3775
3776 if (NILP (tem))
3777 return Qunbound;
3778
3779 switch (type)
3780 {
3781 case RES_TYPE_NUMBER:
3782 return make_number (atoi (SSDATA (tem)));
3783
3784 case RES_TYPE_BOOLEAN_NUMBER:
3785 if (!strcmp (SSDATA (tem), "on")
3786 || !strcmp (SSDATA (tem), "true"))
3787 return make_number (1);
3788 return make_number (atoi (SSDATA (tem)));
3789 break;
3790
3791 case RES_TYPE_FLOAT:
3792 return make_float (atof (SSDATA (tem)));
3793
3794 case RES_TYPE_BOOLEAN:
3795 tem = Fdowncase (tem);
3796 if (!strcmp (SSDATA (tem), "on")
3797 #ifdef HAVE_NS
3798 || !strcmp (SSDATA (tem), "yes")
3799 #endif
3800 || !strcmp (SSDATA (tem), "true"))
3801 return Qt;
3802 else
3803 return Qnil;
3804
3805 case RES_TYPE_STRING:
3806 return tem;
3807
3808 case RES_TYPE_SYMBOL:
3809 /* As a special case, we map the values `true' and `on'
3810 to Qt, and `false' and `off' to Qnil. */
3811 {
3812 Lisp_Object lower;
3813 lower = Fdowncase (tem);
3814 if (!strcmp (SSDATA (lower), "on")
3815 #ifdef HAVE_NS
3816 || !strcmp (SSDATA (lower), "yes")
3817 #endif
3818 || !strcmp (SSDATA (lower), "true"))
3819 return Qt;
3820 else if (!strcmp (SSDATA (lower), "off")
3821 #ifdef HAVE_NS
3822 || !strcmp (SSDATA (lower), "no")
3823 #endif
3824 || !strcmp (SSDATA (lower), "false"))
3825 return Qnil;
3826 else
3827 return Fintern (tem, Qnil);
3828 }
3829
3830 default:
3831 abort ();
3832 }
3833 }
3834 else
3835 return Qunbound;
3836 }
3837 return Fcdr (tem);
3838 }
3839
3840 static Lisp_Object
3841 x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
3842 const char *attribute, const char *class,
3843 enum resource_types type)
3844 {
3845 return x_get_arg (FRAME_X_DISPLAY_INFO (f),
3846 alist, param, attribute, class, type);
3847 }
3848
3849 /* Like x_frame_get_arg, but also record the value in f->param_alist. */
3850
3851 Lisp_Object
3852 x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
3853 Lisp_Object param,
3854 const char *attribute, const char *class,
3855 enum resource_types type)
3856 {
3857 Lisp_Object value;
3858
3859 value = x_get_arg (FRAME_X_DISPLAY_INFO (f), alist, param,
3860 attribute, class, type);
3861 if (! NILP (value) && ! EQ (value, Qunbound))
3862 store_frame_param (f, param, value);
3863
3864 return value;
3865 }
3866
3867
3868 /* Record in frame F the specified or default value according to ALIST
3869 of the parameter named PROP (a Lisp symbol).
3870 If no value is specified for PROP, look for an X default for XPROP
3871 on the frame named NAME.
3872 If that is not found either, use the value DEFLT. */
3873
3874 Lisp_Object
3875 x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
3876 Lisp_Object deflt, const char *xprop, const char *xclass,
3877 enum resource_types type)
3878 {
3879 Lisp_Object tem;
3880
3881 tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
3882 if (EQ (tem, Qunbound))
3883 tem = deflt;
3884 x_set_frame_parameters (f, Fcons (Fcons (prop, tem), Qnil));
3885 return tem;
3886 }
3887
3888
3889
3890 \f
3891 /* NS used to define x-parse-geometry in ns-win.el, but that confused
3892 make-docfile: the documentation string in ns-win.el was used for
3893 x-parse-geometry even in non-NS builds.
3894
3895 With two definitions of x-parse-geometry in this file, various
3896 things still get confused (eg M-x apropos documentation), so that
3897 it is best if the two definitions just share the same doc-string.
3898 */
3899 DEFUN ("x-parse-geometry", Fx_parse_geometry, Sx_parse_geometry, 1, 1, 0,
3900 doc: /* Parse a display geometry string STRING.
3901 Returns an alist of the form ((top . TOP), (left . LEFT) ... ).
3902 The properties returned may include `top', `left', `height', and `width'.
3903 For X, the value of `left' or `top' may be an integer,
3904 or a list (+ N) meaning N pixels relative to top/left corner,
3905 or a list (- N) meaning -N pixels relative to bottom/right corner.
3906 On Nextstep, this just calls `ns-parse-geometry'. */)
3907 (Lisp_Object string)
3908 {
3909 #ifdef HAVE_NS
3910 return call1 (Qns_parse_geometry, string);
3911 #else
3912 int geometry, x, y;
3913 unsigned int width, height;
3914 Lisp_Object result;
3915
3916 CHECK_STRING (string);
3917
3918 geometry = XParseGeometry (SSDATA (string),
3919 &x, &y, &width, &height);
3920 result = Qnil;
3921 if (geometry & XValue)
3922 {
3923 Lisp_Object element;
3924
3925 if (x >= 0 && (geometry & XNegative))
3926 element = Fcons (Qleft, Fcons (Qminus, Fcons (make_number (-x), Qnil)));
3927 else if (x < 0 && ! (geometry & XNegative))
3928 element = Fcons (Qleft, Fcons (Qplus, Fcons (make_number (x), Qnil)));
3929 else
3930 element = Fcons (Qleft, make_number (x));
3931 result = Fcons (element, result);
3932 }
3933
3934 if (geometry & YValue)
3935 {
3936 Lisp_Object element;
3937
3938 if (y >= 0 && (geometry & YNegative))
3939 element = Fcons (Qtop, Fcons (Qminus, Fcons (make_number (-y), Qnil)));
3940 else if (y < 0 && ! (geometry & YNegative))
3941 element = Fcons (Qtop, Fcons (Qplus, Fcons (make_number (y), Qnil)));
3942 else
3943 element = Fcons (Qtop, make_number (y));
3944 result = Fcons (element, result);
3945 }
3946
3947 if (geometry & WidthValue)
3948 result = Fcons (Fcons (Qwidth, make_number (width)), result);
3949 if (geometry & HeightValue)
3950 result = Fcons (Fcons (Qheight, make_number (height)), result);
3951
3952 return result;
3953 #endif /* HAVE_NS */
3954 }
3955
3956
3957 /* Calculate the desired size and position of frame F.
3958 Return the flags saying which aspects were specified.
3959
3960 Also set the win_gravity and size_hint_flags of F.
3961
3962 Adjust height for toolbar if TOOLBAR_P is 1.
3963
3964 This function does not make the coordinates positive. */
3965
3966 #define DEFAULT_ROWS 35
3967 #define DEFAULT_COLS 80
3968
3969 int
3970 x_figure_window_size (struct frame *f, Lisp_Object parms, int toolbar_p)
3971 {
3972 register Lisp_Object tem0, tem1, tem2;
3973 long window_prompting = 0;
3974 Display_Info *dpyinfo = FRAME_X_DISPLAY_INFO (f);
3975
3976 /* Default values if we fall through.
3977 Actually, if that happens we should get
3978 window manager prompting. */
3979 SET_FRAME_COLS (f, DEFAULT_COLS);
3980 FRAME_LINES (f) = DEFAULT_ROWS;
3981 /* Window managers expect that if program-specified
3982 positions are not (0,0), they're intentional, not defaults. */
3983 f->top_pos = 0;
3984 f->left_pos = 0;
3985
3986 /* Ensure that old new_text_cols and new_text_lines will not override the
3987 values set here. */
3988 /* ++KFS: This was specific to W32, but seems ok for all platforms */
3989 f->new_text_cols = f->new_text_lines = 0;
3990
3991 tem0 = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
3992 tem1 = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
3993 tem2 = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
3994 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
3995 {
3996 if (!EQ (tem0, Qunbound))
3997 {
3998 CHECK_NUMBER (tem0);
3999 if (! (0 <= XINT (tem0) && XINT (tem0) <= INT_MAX))
4000 xsignal1 (Qargs_out_of_range, tem0);
4001 FRAME_LINES (f) = XINT (tem0);
4002 }
4003 if (!EQ (tem1, Qunbound))
4004 {
4005 CHECK_NUMBER (tem1);
4006 if (! (0 <= XINT (tem1) && XINT (tem1) <= INT_MAX))
4007 xsignal1 (Qargs_out_of_range, tem1);
4008 SET_FRAME_COLS (f, XINT (tem1));
4009 }
4010 if (!NILP (tem2) && !EQ (tem2, Qunbound))
4011 window_prompting |= USSize;
4012 else
4013 window_prompting |= PSize;
4014 }
4015
4016 f->scroll_bar_actual_width
4017 = FRAME_SCROLL_BAR_COLS (f) * FRAME_COLUMN_WIDTH (f);
4018
4019 /* This used to be done _before_ calling x_figure_window_size, but
4020 since the height is reset here, this was really a no-op. I
4021 assume that moving it here does what Gerd intended (although he
4022 no longer can remember what that was... ++KFS, 2003-03-25. */
4023
4024 /* Add the tool-bar height to the initial frame height so that the
4025 user gets a text display area of the size he specified with -g or
4026 via .Xdefaults. Later changes of the tool-bar height don't
4027 change the frame size. This is done so that users can create
4028 tall Emacs frames without having to guess how tall the tool-bar
4029 will get. */
4030 if (toolbar_p && FRAME_TOOL_BAR_LINES (f))
4031 {
4032 int margin, relief, bar_height;
4033
4034 relief = (tool_bar_button_relief >= 0
4035 ? tool_bar_button_relief
4036 : DEFAULT_TOOL_BAR_BUTTON_RELIEF);
4037
4038 if (RANGED_INTEGERP (1, Vtool_bar_button_margin, INT_MAX))
4039 margin = XFASTINT (Vtool_bar_button_margin);
4040 else if (CONSP (Vtool_bar_button_margin)
4041 && RANGED_INTEGERP (1, XCDR (Vtool_bar_button_margin), INT_MAX))
4042 margin = XFASTINT (XCDR (Vtool_bar_button_margin));
4043 else
4044 margin = 0;
4045
4046 bar_height = DEFAULT_TOOL_BAR_IMAGE_HEIGHT + 2 * margin + 2 * relief;
4047 FRAME_LINES (f) += (bar_height + FRAME_LINE_HEIGHT (f) - 1) / FRAME_LINE_HEIGHT (f);
4048 }
4049
4050 compute_fringe_widths (f, 0);
4051
4052 FRAME_PIXEL_WIDTH (f) = FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f, FRAME_COLS (f));
4053 FRAME_PIXEL_HEIGHT (f) = FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f, FRAME_LINES (f));
4054
4055 tem0 = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
4056 tem1 = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
4057 tem2 = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
4058 if (! EQ (tem0, Qunbound) || ! EQ (tem1, Qunbound))
4059 {
4060 if (EQ (tem0, Qminus))
4061 {
4062 f->top_pos = 0;
4063 window_prompting |= YNegative;
4064 }
4065 else if (CONSP (tem0) && EQ (XCAR (tem0), Qminus)
4066 && CONSP (XCDR (tem0))
4067 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem0)), INT_MAX))
4068 {
4069 f->top_pos = - XINT (XCAR (XCDR (tem0)));
4070 window_prompting |= YNegative;
4071 }
4072 else if (CONSP (tem0) && EQ (XCAR (tem0), Qplus)
4073 && CONSP (XCDR (tem0))
4074 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem0))))
4075 {
4076 f->top_pos = XINT (XCAR (XCDR (tem0)));
4077 }
4078 else if (EQ (tem0, Qunbound))
4079 f->top_pos = 0;
4080 else
4081 {
4082 CHECK_TYPE_RANGED_INTEGER (int, tem0);
4083 f->top_pos = XINT (tem0);
4084 if (f->top_pos < 0)
4085 window_prompting |= YNegative;
4086 }
4087
4088 if (EQ (tem1, Qminus))
4089 {
4090 f->left_pos = 0;
4091 window_prompting |= XNegative;
4092 }
4093 else if (CONSP (tem1) && EQ (XCAR (tem1), Qminus)
4094 && CONSP (XCDR (tem1))
4095 && RANGED_INTEGERP (-INT_MAX, XCAR (XCDR (tem1)), INT_MAX))
4096 {
4097 f->left_pos = - XINT (XCAR (XCDR (tem1)));
4098 window_prompting |= XNegative;
4099 }
4100 else if (CONSP (tem1) && EQ (XCAR (tem1), Qplus)
4101 && CONSP (XCDR (tem1))
4102 && TYPE_RANGED_INTEGERP (int, XCAR (XCDR (tem1))))
4103 {
4104 f->left_pos = XINT (XCAR (XCDR (tem1)));
4105 }
4106 else if (EQ (tem1, Qunbound))
4107 f->left_pos = 0;
4108 else
4109 {
4110 CHECK_TYPE_RANGED_INTEGER (int, tem1);
4111 f->left_pos = XINT (tem1);
4112 if (f->left_pos < 0)
4113 window_prompting |= XNegative;
4114 }
4115
4116 if (!NILP (tem2) && ! EQ (tem2, Qunbound))
4117 window_prompting |= USPosition;
4118 else
4119 window_prompting |= PPosition;
4120 }
4121
4122 if (window_prompting & XNegative)
4123 {
4124 if (window_prompting & YNegative)
4125 f->win_gravity = SouthEastGravity;
4126 else
4127 f->win_gravity = NorthEastGravity;
4128 }
4129 else
4130 {
4131 if (window_prompting & YNegative)
4132 f->win_gravity = SouthWestGravity;
4133 else
4134 f->win_gravity = NorthWestGravity;
4135 }
4136
4137 f->size_hint_flags = window_prompting;
4138
4139 return window_prompting;
4140 }
4141
4142
4143
4144 #endif /* HAVE_WINDOW_SYSTEM */
4145
4146 void
4147 frame_make_pointer_invisible (void)
4148 {
4149 if (! NILP (Vmake_pointer_invisible))
4150 {
4151 struct frame *f;
4152 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4153 return;
4154
4155 f = SELECTED_FRAME ();
4156 if (f && !f->pointer_invisible
4157 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4158 {
4159 f->mouse_moved = 0;
4160 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 1);
4161 f->pointer_invisible = 1;
4162 }
4163 }
4164 }
4165
4166 void
4167 frame_make_pointer_visible (void)
4168 {
4169 /* We don't check Vmake_pointer_invisible here in case the
4170 pointer was invisible when Vmake_pointer_invisible was set to nil. */
4171 struct frame *f;
4172
4173 if (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)))
4174 return;
4175
4176 f = SELECTED_FRAME ();
4177 if (f && f->pointer_invisible && f->mouse_moved
4178 && FRAME_TERMINAL (f)->toggle_invisible_pointer_hook)
4179 {
4180 FRAME_TERMINAL (f)->toggle_invisible_pointer_hook (f, 0);
4181 f->pointer_invisible = 0;
4182 }
4183 }
4184
4185 DEFUN ("frame-pointer-visible-p", Fframe_pointer_visible_p,
4186 Sframe_pointer_visible_p, 0, 1, 0,
4187 doc: /* Return t if the mouse pointer displayed on FRAME is visible.
4188 Otherwise it returns nil. FRAME omitted or nil means the
4189 selected frame. This is useful when `make-pointer-invisible' is set. */)
4190 (Lisp_Object frame)
4191 {
4192 if (NILP (frame))
4193 frame = selected_frame;
4194
4195 CHECK_FRAME (frame);
4196
4197 return (XFRAME (frame)->pointer_invisible ? Qnil : Qt);
4198 }
4199
4200 \f
4201 /***********************************************************************
4202 Initialization
4203 ***********************************************************************/
4204
4205 void
4206 syms_of_frame (void)
4207 {
4208 DEFSYM (Qframep, "framep");
4209 DEFSYM (Qframe_live_p, "frame-live-p");
4210 DEFSYM (Qexplicit_name, "explicit-name");
4211 DEFSYM (Qheight, "height");
4212 DEFSYM (Qicon, "icon");
4213 DEFSYM (Qminibuffer, "minibuffer");
4214 DEFSYM (Qmodeline, "modeline");
4215 DEFSYM (Qonly, "only");
4216 DEFSYM (Qwidth, "width");
4217 DEFSYM (Qgeometry, "geometry");
4218 DEFSYM (Qicon_left, "icon-left");
4219 DEFSYM (Qicon_top, "icon-top");
4220 DEFSYM (Qtooltip, "tooltip");
4221 DEFSYM (Qleft, "left");
4222 DEFSYM (Qright, "right");
4223 DEFSYM (Quser_position, "user-position");
4224 DEFSYM (Quser_size, "user-size");
4225 DEFSYM (Qwindow_id, "window-id");
4226 #ifdef HAVE_X_WINDOWS
4227 DEFSYM (Qouter_window_id, "outer-window-id");
4228 #endif
4229 DEFSYM (Qparent_id, "parent-id");
4230 DEFSYM (Qx, "x");
4231 DEFSYM (Qw32, "w32");
4232 DEFSYM (Qpc, "pc");
4233 DEFSYM (Qmac, "mac");
4234 DEFSYM (Qns, "ns");
4235 DEFSYM (Qvisible, "visible");
4236 DEFSYM (Qbuffer_predicate, "buffer-predicate");
4237 DEFSYM (Qbuffer_list, "buffer-list");
4238 DEFSYM (Qburied_buffer_list, "buried-buffer-list");
4239 DEFSYM (Qdisplay_type, "display-type");
4240 DEFSYM (Qbackground_mode, "background-mode");
4241 DEFSYM (Qnoelisp, "noelisp");
4242 DEFSYM (Qtty_color_mode, "tty-color-mode");
4243 DEFSYM (Qtty, "tty");
4244 DEFSYM (Qtty_type, "tty-type");
4245
4246 DEFSYM (Qface_set_after_frame_default, "face-set-after-frame-default");
4247
4248 DEFSYM (Qfullwidth, "fullwidth");
4249 DEFSYM (Qfullheight, "fullheight");
4250 DEFSYM (Qfullboth, "fullboth");
4251 DEFSYM (Qmaximized, "maximized");
4252 DEFSYM (Qx_resource_name, "x-resource-name");
4253 DEFSYM (Qx_frame_parameter, "x-frame-parameter");
4254
4255 DEFSYM (Qterminal, "terminal");
4256 DEFSYM (Qterminal_live_p, "terminal-live-p");
4257
4258 #ifdef HAVE_NS
4259 DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
4260 #endif
4261
4262 {
4263 int i;
4264
4265 for (i = 0; i < sizeof (frame_parms) / sizeof (frame_parms[0]); i++)
4266 {
4267 Lisp_Object v = intern_c_string (frame_parms[i].name);
4268 if (frame_parms[i].variable)
4269 {
4270 *frame_parms[i].variable = v;
4271 staticpro (frame_parms[i].variable);
4272 }
4273 Fput (v, Qx_frame_parameter, make_number (i));
4274 }
4275 }
4276
4277 #ifdef HAVE_WINDOW_SYSTEM
4278 DEFVAR_LISP ("x-resource-name", Vx_resource_name,
4279 doc: /* The name Emacs uses to look up X resources.
4280 `x-get-resource' uses this as the first component of the instance name
4281 when requesting resource values.
4282 Emacs initially sets `x-resource-name' to the name under which Emacs
4283 was invoked, or to the value specified with the `-name' or `-rn'
4284 switches, if present.
4285
4286 It may be useful to bind this variable locally around a call
4287 to `x-get-resource'. See also the variable `x-resource-class'. */);
4288 Vx_resource_name = Qnil;
4289
4290 DEFVAR_LISP ("x-resource-class", Vx_resource_class,
4291 doc: /* The class Emacs uses to look up X resources.
4292 `x-get-resource' uses this as the first component of the instance class
4293 when requesting resource values.
4294
4295 Emacs initially sets `x-resource-class' to "Emacs".
4296
4297 Setting this variable permanently is not a reasonable thing to do,
4298 but binding this variable locally around a call to `x-get-resource'
4299 is a reasonable practice. See also the variable `x-resource-name'. */);
4300 Vx_resource_class = build_string (EMACS_CLASS);
4301
4302 DEFVAR_LISP ("frame-alpha-lower-limit", Vframe_alpha_lower_limit,
4303 doc: /* The lower limit of the frame opacity (alpha transparency).
4304 The value should range from 0 (invisible) to 100 (completely opaque).
4305 You can also use a floating number between 0.0 and 1.0.
4306 The default is 20. */);
4307 Vframe_alpha_lower_limit = make_number (20);
4308 #endif
4309
4310 DEFVAR_LISP ("default-frame-alist", Vdefault_frame_alist,
4311 doc: /* Alist of default values for frame creation.
4312 These may be set in your init file, like this:
4313 (setq default-frame-alist '((width . 80) (height . 55) (menu-bar-lines . 1)))
4314 These override values given in window system configuration data,
4315 including X Windows' defaults database.
4316 For values specific to the first Emacs frame, see `initial-frame-alist'.
4317 For window-system specific values, see `window-system-default-frame-alist'.
4318 For values specific to the separate minibuffer frame, see
4319 `minibuffer-frame-alist'.
4320 The `menu-bar-lines' element of the list controls whether new frames
4321 have menu bars; `menu-bar-mode' works by altering this element.
4322 Setting this variable does not affect existing frames, only new ones. */);
4323 Vdefault_frame_alist = Qnil;
4324
4325 DEFVAR_LISP ("default-frame-scroll-bars", Vdefault_frame_scroll_bars,
4326 doc: /* Default position of scroll bars on this window-system. */);
4327 #ifdef HAVE_WINDOW_SYSTEM
4328 #if defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA) || (defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS))
4329 /* MS-Windows, Mac OS X, and GTK have scroll bars on the right by
4330 default. */
4331 Vdefault_frame_scroll_bars = Qright;
4332 #else
4333 Vdefault_frame_scroll_bars = Qleft;
4334 #endif
4335 #else
4336 Vdefault_frame_scroll_bars = Qnil;
4337 #endif
4338
4339 DEFVAR_LISP ("terminal-frame", Vterminal_frame,
4340 doc: /* The initial frame-object, which represents Emacs's stdout. */);
4341
4342 DEFVAR_LISP ("mouse-position-function", Vmouse_position_function,
4343 doc: /* If non-nil, function to transform normal value of `mouse-position'.
4344 `mouse-position' calls this function, passing its usual return value as
4345 argument, and returns whatever this function returns.
4346 This abnormal hook exists for the benefit of packages like `xt-mouse.el'
4347 which need to do mouse handling at the Lisp level. */);
4348 Vmouse_position_function = Qnil;
4349
4350 DEFVAR_LISP ("mouse-highlight", Vmouse_highlight,
4351 doc: /* If non-nil, clickable text is highlighted when mouse is over it.
4352 If the value is an integer, highlighting is only shown after moving the
4353 mouse, while keyboard input turns off the highlight even when the mouse
4354 is over the clickable text. However, the mouse shape still indicates
4355 when the mouse is over clickable text. */);
4356 Vmouse_highlight = Qt;
4357
4358 DEFVAR_LISP ("make-pointer-invisible", Vmake_pointer_invisible,
4359 doc: /* If non-nil, make pointer invisible while typing.
4360 The pointer becomes visible again when the mouse is moved. */);
4361 Vmake_pointer_invisible = Qt;
4362
4363 DEFVAR_LISP ("delete-frame-functions", Vdelete_frame_functions,
4364 doc: /* Functions to be run before deleting a frame.
4365 The functions are run with one arg, the frame to be deleted.
4366 See `delete-frame'.
4367
4368 Note that functions in this list may be called just before the frame is
4369 actually deleted, or some time later (or even both when an earlier function
4370 in `delete-frame-functions' (indirectly) calls `delete-frame'
4371 recursively). */);
4372 Vdelete_frame_functions = Qnil;
4373 DEFSYM (Qdelete_frame_functions, "delete-frame-functions");
4374
4375 DEFVAR_LISP ("menu-bar-mode", Vmenu_bar_mode,
4376 doc: /* Non-nil if Menu-Bar mode is enabled.
4377 See the command `menu-bar-mode' for a description of this minor mode.
4378 Setting this variable directly does not take effect;
4379 either customize it (see the info node `Easy Customization')
4380 or call the function `menu-bar-mode'. */);
4381 Vmenu_bar_mode = Qt;
4382
4383 DEFVAR_LISP ("tool-bar-mode", Vtool_bar_mode,
4384 doc: /* Non-nil if Tool-Bar mode is enabled.
4385 See the command `tool-bar-mode' for a description of this minor mode.
4386 Setting this variable directly does not take effect;
4387 either customize it (see the info node `Easy Customization')
4388 or call the function `tool-bar-mode'. */);
4389 #ifdef HAVE_WINDOW_SYSTEM
4390 Vtool_bar_mode = Qt;
4391 #else
4392 Vtool_bar_mode = Qnil;
4393 #endif
4394
4395 DEFVAR_KBOARD ("default-minibuffer-frame", Vdefault_minibuffer_frame,
4396 doc: /* Minibufferless frames use this frame's minibuffer.
4397
4398 Emacs cannot create minibufferless frames unless this is set to an
4399 appropriate surrogate.
4400
4401 Emacs consults this variable only when creating minibufferless
4402 frames; once the frame is created, it sticks with its assigned
4403 minibuffer, no matter what this variable is set to. This means that
4404 this variable doesn't necessarily say anything meaningful about the
4405 current set of frames, or where the minibuffer is currently being
4406 displayed.
4407
4408 This variable is local to the current terminal and cannot be buffer-local. */);
4409
4410 DEFVAR_BOOL ("focus-follows-mouse", focus_follows_mouse,
4411 doc: /* Non-nil if window system changes focus when you move the mouse.
4412 You should set this variable to tell Emacs how your window manager
4413 handles focus, since there is no way in general for Emacs to find out
4414 automatically. See also `mouse-autoselect-window'. */);
4415 focus_follows_mouse = 0;
4416
4417 staticpro (&Vframe_list);
4418
4419 defsubr (&Sframep);
4420 defsubr (&Sframe_live_p);
4421 defsubr (&Swindow_system);
4422 defsubr (&Smake_terminal_frame);
4423 defsubr (&Shandle_switch_frame);
4424 defsubr (&Sselect_frame);
4425 defsubr (&Sselected_frame);
4426 defsubr (&Sframe_list);
4427 defsubr (&Snext_frame);
4428 defsubr (&Sprevious_frame);
4429 defsubr (&Sdelete_frame);
4430 defsubr (&Smouse_position);
4431 defsubr (&Smouse_pixel_position);
4432 defsubr (&Sset_mouse_position);
4433 defsubr (&Sset_mouse_pixel_position);
4434 #if 0
4435 defsubr (&Sframe_configuration);
4436 defsubr (&Srestore_frame_configuration);
4437 #endif
4438 defsubr (&Smake_frame_visible);
4439 defsubr (&Smake_frame_invisible);
4440 defsubr (&Siconify_frame);
4441 defsubr (&Sframe_visible_p);
4442 defsubr (&Svisible_frame_list);
4443 defsubr (&Sraise_frame);
4444 defsubr (&Slower_frame);
4445 defsubr (&Sredirect_frame_focus);
4446 defsubr (&Sframe_focus);
4447 defsubr (&Sframe_parameters);
4448 defsubr (&Sframe_parameter);
4449 defsubr (&Smodify_frame_parameters);
4450 defsubr (&Sframe_char_height);
4451 defsubr (&Sframe_char_width);
4452 defsubr (&Sframe_pixel_height);
4453 defsubr (&Sframe_pixel_width);
4454 defsubr (&Stool_bar_pixel_width);
4455 defsubr (&Sset_frame_height);
4456 defsubr (&Sset_frame_width);
4457 defsubr (&Sset_frame_size);
4458 defsubr (&Sset_frame_position);
4459 defsubr (&Sframe_pointer_visible_p);
4460
4461 #ifdef HAVE_WINDOW_SYSTEM
4462 defsubr (&Sx_get_resource);
4463 defsubr (&Sx_parse_geometry);
4464 #endif
4465
4466 }