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