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