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