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