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